wheresrhys
wheresrhys

Reputation: 23550

Regular expression to match not the beginning/end of a line

I would like a regular expression to match only " that

I guess I need to use lookbehind and lookahead.

So matches the " in

zfgjhsgaf jhsa gd " gjhygf" hgf

But not in

"gjhgjkgjhgjhgkk"

      "dfsdfsdf"   

Upvotes: 1

Views: 466

Answers (5)

xni
xni

Reputation: 2075

I think whis re is expressive enougth :

^\s*\S+.*innertext.*\S+\s*$

Upvotes: 0

Peteris
Peteris

Reputation: 3756

This one should work

^\s*[^"].*".*[^"]\s*$

Upvotes: 0

Seth Robertson
Seth Robertson

Reputation: 31471

^\s*"?.*\S.*(").*?\S.*?"?\s*$

Which supports matching ' "foo"bar" ' assuming that is something that you want to find.

Oh, and it only matches if $1 is set

Upvotes: 0

stema
stema

Reputation: 93026

See this here

(?<!^)"(?!\s*$)

at Regexr

It works not for the whitespace after beginning of the line. As BoltClock mentioned, variable length look behind is supported only by few engines (I know only .net).

If you use a regex that support it, you can use

(?<!^.*)"(?!\s*$)

A good documentation for look ahead/behind is here in the perldoc.perl.org/perlretut.html#Looking-ahead-and-looking-behind

Upvotes: 0

BoltClock
BoltClock

Reputation: 724252

For Eclipse, try finding by this regex:

(?<!^\s*)"(?!\s*$)

And replacing with:

\"

Upvotes: 2

Related Questions