ycomp
ycomp

Reputation: 8573

How to condense this regex with a bunch of repeated segements?

How would I condense this? I tried using brackets and /2 but that didn't seem to work. Anyone know? This is kind of ugly.

^(\$|)[A-Z0-9_\- ]*\t[0-9\.\-]*\t[0-9\.\-]*\t[0-9\.\-]*\t[0-9\.\-]*\t[0-9\.\-]*\t[0-9\.\-]*\t

I'm using a Perl 6.18 compatible (I think it's .18) regex engine.

Upvotes: 0

Views: 149

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Use a non-capturing group and repetition quantifier.

^(\$|)[A-Z0-9_\- ]*\t(?:[0-9\.\-]*\t){6}

OR

^\$?[-A-Z0-9_ ]*\t(?:[0-9.-]*\t){6}

Upvotes: 1

Related Questions