I need a RegExp which matches a word or multiple words in quotes.
[\w]* matches a word
"[\w\W&&[^"]]*" matches multiple words in quotes.
(btw, not sure why \w\W works, but not a simple . (which should match all characters)
So how do i combine these two regexp?
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
Firstly, double quote character is nothing special in regex - it's just another character, so it doesn't need escaping from the perspective of regex. However, because Java uses double quotes to delimit String constants, if you want to create a string in Java with a double quote in it, you must escape them.
the regex looks for a quote mark " then it looks for any possible group of letters thats not " until it finds icon. and any possible group of letters that is not " it then looks for a closing "
Does "[^"]+"
do what you want? (Match a double-quote, match one or more chars that are not double quotes, then match a second double-quote.)
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