I'm writing a regex to to capture all text in a multi line file between @id=1
and #
. When I say #
I mean the first solitary #
at the start of a line with an optional space afterwards. I'm programming in dart. The regex I came up with is as follows:
/^@id ?= ?1$(.*)^# ?$/gms
I'm getting some strange results. On RegExr.com the regex has a match, but it does not stop at the first # ?$
. In dart, I get no match at all. Here is my dart code
var matchContents =
RegExp(r'^@id ?= ?1$(.*)^# ?$', multiLine: true, dotAll: true);
var testString = '''
alskdfkldsfjd
# thekt nect
@id=2
akdfjdkf
adlksfj
@id=1
adksfklasdjf // This line should be captured
asdlkfjdkfj // And this one
@id=3 // this one
dkfjadklfja // And this one
#
kdsalfjaslkdf
#
''';
print(matchContents.hasMatch(testString)); // This checks if there is any match (it's currently false)
Why isn't this working and how do I fix it?