0

I am a beginner in perl and I am looking on how to search for multiple special characters in a file using Regex. Basically, I have a closing tag /> which I need to verify in a file. I have read that when we have special characters, we need to precede using '\'. But I have two special characters together and I am not sure how to have this check done.

I am using something like below, including /> in-between /\""/ but its not working :

$line =~ /\/>/ 

Could someone help me with this pattern matching using Regex?

Joundill
  • 6,828
  • 12
  • 36
  • 50
  • 1
    https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?rq=1 – Isaac Sep 26 '17 at 04:11
  • 5
    Don't parse XML/HTML/... with regex. Don't. See the link in Isaac's comment and run for `XML::LibXML` or `XML::Twig` or one of the number of HTML modules. Having said that, `$line =~ m{/>}` takes care of _that_ (one) example: Use a delimiter other than `/`, while `>` isn't special. – zdim Sep 26 '17 at 04:22

1 Answers1

-1

I believe \Y or \Q..\E is your friend here.

  /text\Y$literal\Ytext/
  /\Q.*\Etext/

\Y listed as without any runtime variable interpolations. This means all perl variables will be treated as literal symbols.

\Q..\E listed as (disable) pattern metacharacter. This means usual regex special characters will be treated as literal symbols without the needing to escape them.

http://perldoc.perl.org/perlre.html

hoffmeister
  • 612
  • 4
  • 10