i want to remove anything between "?" and "/"
my text is "hi?0/hello/hi"
i need to see this out put
"hi?/hello/hi"
My Code Is
key.replaceAll("\\?.*/","?/");
but my Output Is
"hi?/hi"
whats wrong?
To eliminate text before a given character, type the character preceded by an asterisk (*char). To remove text after a certain character, type the character followed by an asterisk (char*). To delete a substring between two characters, type an asterisk surrounded by 2 characters (char*char).
To extract part string between two different characters, you can do as this: Select a cell which you will place the result, type this formula =MID(LEFT(A1,FIND(">",A1)-1),FIND("<",A1)+1,LEN(A1)), and press Enter key. Note: A1 is the text cell, > and < are the two characters you want to extract string between.
Extract text before or after space with formula in Excel Select a blank cell, and type this formula =LEFT(A1,(FIND(" ",A1,1)-1)) (A1 is the first cell of the list you want to extract text) , and press Enter button.
You are using greedy matching, so it matches up to the next slash too. Try:
key.replaceAll("\\?.*?/","?/");
An alternative still using greedy matching is to match any character except /
:
key.replaceAll("\\?[^/]*/","?/");
Use this:
key.replaceAll("\\?.*?/","?/")
You can read more about greedy
and non greedy
matching here
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