on-internet
← Community

Using variable to match specific pattern within regex

Stack Overflow ·

I would like to use a variable to match patterns with a regular expression. The patterns I want to match are: >crypt29_1 and >crypt29_2 my $var = 'crypt29'; my $pattern = ">".$var."_"."*"; $string =~ m/$pattern/; matches >crypt29_1, >crypt29_2 as well as >crypt290_2 and >crypt2914_2. How can I make the match specific to match only >crypt29_1 and >crypt29_2.

Comments

Sign in or sign up to comment and upvote.

No comments yet.