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
?
We can remove part of the string using REPLACE() function. We can use this function if we know the exact character of the string to remove. REMOVE(): This function replaces all occurrences of a substring within a new substring.
If you are having a string with special characters and want's to remove/replace them then you can use regex for that. Use this code: Regex. Replace(your String, @"[^0-9a-zA-Z]+", "")
JavaScript String replace() The replace() method is one of the most commonly used techniques to remove the character from a string in javascript. The replace() method takes two parameters, the first of which is the character to be replaced and the second of which is the character to replace it with.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With