Question

I've got the following Regex:

.*?,

And here is some of the data I am working with:

"bagel-mssql-iscsi.private.hostname.ca","3636634643","8.8.8.8"
"cecs-admin.prt.hostname.ca","3636634643","8.8.8.8"
"cecs-admin2.prt.hostname.ca","3636634643","8.8.8.8"

The above data has been censored from the original data.

I want to match:

"bagel-mssql-iscsi.private.hostname.ca",
"cecs-admin.prt.hostname.ca",
"cecs-admin2.prt.hostname.ca",

The problem is that my regex is also matching the numerical value after the hostnames. What can I do so that only the first occurrence of every line is matched. Or an alternative method that would work with this type of data also would work.

Was it helpful?

Solution

Your regex would be,

^".*?",

DEMO

Explanation:

  • ^ Asserts that we are at the start.
  • " Literal double quotes.
  • .*? Reluctant match of any character zero or more times.
  • ", Literal " followed by a comma.

OTHER TIPS

You need to anchor to the beginning of the line:

^.*?,

Use ^ anchor which matches only at the beginning of the line:

^.*?,

enter image description here

The Regex Filter below may help:

^\"(\S*?)\",

http://regex101.com/r/dZ3gH8/1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top