Jim Belton
Jim Belton

Reputation: 231

Does dart support perl style regular expression and match operator syntax?

Can you write anything like:

string =~ /^.s*(.\S+)/;
print "First word is '$1'";

What is the syntax in dart? Or must one use the raw objects?

Upvotes: 2

Views: 727

Answers (3)

pogo
pogo

Reputation: 1550

I am not sure about dart. But from here

http://www.dartlang.org/docs/dart-up-and-running/ch03.html#ch03-strings-and-regular-expressions

it looks like the syntax is same as any other language.

Upvotes: 1

Erik Corry
Erik Corry

Reputation: 650

Dart doesn't have literal regexp syntax:

/foo\s*\(bar\)/

But it does have raw strings, and you should use them:

new RegExp(r"foo\s*\(bar\)");

without raw strings, you would have to double the backslashes and (if you remembered to do that) you would have:

new RegExp("foo\\s*\\(bar\\)");

Upvotes: 1

Ladicek
Ladicek

Reputation: 6597

There are no regexp literals and match operators in Dart. So yes, you have to use the RegExp object and its siblings.

Upvotes: 3

Related Questions