Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegExp match one Word or Multiple Words in Quotes

Tags:

regex

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?

like image 442
JP-Ulm Avatar asked Nov 28 '08 12:11

JP-Ulm


People also ask

How do you match expressions in regex?

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).

How do you match double quotes in regex?

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.

What is quotation mark in regex?

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 "


1 Answers

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.)

like image 125
genehack Avatar answered Oct 05 '22 22:10

genehack