I'm trying to extract the following data.
Sample dataset
name ID: john
name ID: peter
I want to be able to extract out peter using a regex.
I'm only able to get john using this regex - name ID:\s(.*?)\s
but is not able to extract only peter out.
I'm trying to extract the following data.
Sample dataset
name ID: john
name ID: peter
I want to be able to extract out peter using a regex.
I'm only able to get john using this regex - name ID:\s(.*?)\s
but is not able to extract only peter out.
If these are single line items, you could anchor the expressions to the line boundaries:
^ expression $
... will do that, so:
^name ID: (.*)$
Make sure your expression is using the Multi-Line flag. Since you haven't specified the language or regex library you're using, I'm not 100% sure what the syntax would be in your case.
For C# you can pass the RegexOptions.Multiline to the constructor of the regex. In JavaScript you use the /expression/m syntax to set this option. In some libraries you can add (?m:) to the start of the expression.