开发者

reg ex newby - how do you specify to match a characters but not include it in the output?

开发者 https://www.devze.com 2023-01-11 19:14 出处:网络
Really simple situation: Eg. in this string: my dog said \"woof\" today I would like to get the string in quotes, but without the quotes...

Really simple situation:

Eg. in this string:

my dog said "woof" today

I would like to get the string in quotes, but without the quotes...

--- more detail ---

Unfortunately the regex is via 3rd party software so I don't know the underlying engi开发者_如何学Pythonne.

Here's the string:

href="http://pagingdrgupta.blogs.cnn.com/2010/08/17/dengue-fever-increases-in-florida/?hpt=T2">Dengue outbreak 

Current regex:

(https?://)?([-\w]+(\.\w[-\w]*)+|([a-z0-9]([-a-z0-9]*[a-z0-9])?\.))+(com|edu|biz|gov|in(t|fo)|mil|net|org|[a-z][a-z]\.[a-z][a-z])\S*)

this returns:

http:.../?hpt=T2">Dengue

Adding " to start and end of regex works, but includes the ".

Perhaps there's another way?


This is going to depend on the "flavour" of regex that you are using. If your regex engine supports lookarounds (positive lookbehind, positive lookahead, negative lookbehind, and negative lookahead), you can do this.

The syntax also varies by flavour, so if you edit your question and/or tags to show what language you're working in, you can get a more specific answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消