Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  102] [ 7]  / answers: 1 / hits: 26627  / 9 Years ago, thu, february 5, 2015, 12:00:00

If I have a string which looks like this:



var myString = '73gf9y::-8auhTHIS_IS_WHAT_I_WANT'


What regex would I need to end up with:



'THIS_IS_WHAT_I_WANT'


The first part of my String will always be a random assortment of characters. Is there some regex which will remove everything up to THIS?


More From » regex

 Answers
49

So you want to strip out everything from beginning to the first uppercase letter?



console.log(myString.replace(/^[^A-Z]+/,));



THIS_IS_WHAT_I_WANT




See fiddle, well I'm not sure if that is what you want :)






To strip out everything from start to the first occuring uppercase string, that's followed by _ try:



myString.replace(/^.*?(?=[A-Z]+_)/,);


This uses a lookahead. See Test at regex101;


[#67934] Tuesday, February 3, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jackie

Total Points: 442
Total Questions: 107
Total Answers: 94

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
jackie questions
Sat, Sep 18, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
;