質問

"[a-zA-Z0-9]*"

which I wish to match the pattern of the form

"testing" 

But my regex is not matching any of these strings. Where I'm making the mistake?

Thanks in advance.

役に立ちましたか?

解決

if your requirement is "matching" not "extracting":

^"[a-zA-Z0-9"]*"$ would be the regex you need.

note that since your 2nd example has nested double quotes, you need " in your []

test with grep:

kent$  echo '"testing"
"testing123"hello""
'|grep -E '^"[a-zA-Z0-9"]*"$'
"testing"
"testing123"hello""

if you want to extract things between double quotes, you need to explain, what do you want to get in your 2nd example.

EDIT

if you just want to extract the things between double quote:

(?<=")[^"]* 

is what you are looking for.

still testing with grep:

kent$  echo '"xxx bbb _ foo bar"'|grep -Po '(?<=")[^"]*'
xxx bbb _ foo bar

他のヒント

I think you may have to escape the

"

with a

\

as in:

\"[a-zA-z0-9]*\"

This will give you three matches as expected.

See this http://rubular.com/r/WW9IKTb0Xa

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top