Ian
Ian

Reputation: 11

Regex for everything in quotations only if certain string appears

for example i have two lines

" dswda__12 ( Linux, 22 ) sasa "

and

" dshbjsd12_22 ( Windows, 21 ) sws " 

I want to match everything insides quotes for only line with word containing Linux using regex pattern only,

Im only new and have tried ((["'][.*])(\<Linux\>)([.*]["'])) however cant figure it out

Upvotes: 1

Views: 36

Answers (2)

Aziz
Aziz

Reputation: 20765

The following pattern should work:

['"](.*Linux.*)['"]

The first and last ['"] are used to match opening and closing quotation marks (single or double). The .* before and after the word Linux is to match everything inside the quotation marks that surrounds the word Linux. The braces ( and ) are to capture the part inside the quotation marks only.

Here's the test using your example inputs: http://regexr.com/633sg

Upvotes: 0

Tranbi
Tranbi

Reputation: 12731

What are your constraints exactly? Do quotes have to be part of the match? Matching line with Linux is straightforward:

.*Linux.*

Note that it is case sensitive. You can add more elements and be more specific though.
Also what language do you use?

You can test expressions here: https://regex101.com/r/01R4b2/1

Upvotes: 0

Related Questions