Live data from Hacker News

Best syntax for a regex literal

news.ycombinator.com

1–5 of 5 posts

Re: Best syntax for a regex literal

#2
"^[AEIOU]{1}.+[aeiou]{1}$" or `(^[AEIOU]{1}.+[aeiou]{1}$) or re (^[AEIOU]{1}.+[aeiou]{1}$) or @(^[AEIOU]{1}.+[aeiou]{1}$) or or /^[AEIOU]{1}.+[aeiou]{1}$/ or (re:^[AEIOU]{1}.+[aeiou]{1}$) or `^[AEIOU]{1}.+[aeiou]{1}$`

all look ugly. I would either use a triple distinct character set like python with """^[AEIOU]{1}.+[aeiou]{1}$""" or ~~~^[AEIOU]{1}.+[aeiou]{1}$~~~ but for simplicity you should use the re(...) one because you can intuitively know where the wrapper starts and ends.

Re: Best syntax for a regex literal

#3

"^[AEIOU]{1}.+[aeiou]{1}$" or `(^[AEIOU]{1}.+[aeiou]{1}$) or re (^[AEIOU]{1}.+[aeiou]{1}$) or @(^[AEIOU]{1}.+[aeiou]{1}$) or or /^[AEIOU]{1}.+[aeiou]{1}$/ or (re:^[AEIOU]{1}.+[aeiou]{1}$) or `^[AEIOU]{1}.+[aeiou]{1}$` all look ugly. I would either use a triple distinct character set like python with """^[AEIOU]{1}.+[aeiou]{1}$""" or ~~~^[AEIOU]{1}.+[aeiou]{1}$~~~ but for simplicity you should use the re(...) one beca…

Thanks

Re: Best syntax for a regex literal

#4
post #3

"^[AEIOU]{1}.+[aeiou]{1}$" or `(^[AEIOU]{1}.+[aeiou]{1}$) or re (^[AEIOU]{1}.+[aeiou]{1}$) or @(^[AEIOU]{1}.+[aeiou]{1}$) or or /^[AEIOU]{1}.+[aeiou]{1}$/ or (re:^[AEIOU]{1}.+[aeiou]{1}$) or `^[AEIOU]{1}.+[aeiou]{1}$` all look ugly. I would either use a triple distinct character set like python with """^[AEIOU]{1}.+[aeiou]{1}$""" or ~~~^[AEIOU]{1}.+[aeiou]{1}$~~~ but for simplicity you should use the re(...) one beca…

Thanks

I also use an alternative regex syntax to improve readability. For example:

re ("abc" | ["0"-"9"]+)

means this:

/abc|[0-9]+/

(You can put whitespaceses into the literal)

Re: Best syntax for a regex literal

#5
post #4
post #3

Earlier quoted context omitted.

Thanks

I also use an alternative regex syntax to improve readability. For example: re ("abc" | ["0"-"9"]+) means this: /abc|[0-9]+/ (You can put whitespaceses into the literal)

PCRE have the /x modifier to allow whitespace and comments.

When reinventing the wheel, it's hard to top what other do already pretty well. Also, be warned people have to learn your syntax and this will probably stop them using it.