Regex that will match first case on every line.
-
21-12-2019 - |
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.
Solution
Your regex would be,
^".*?",
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:
^.*?,
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow