Help with using expression in gsub function
1
0
Entering edit mode
9.0 years ago
M K ▴ 660

Help with understanding the expressions in the following gsub function

("-__-|\\+__\\+","+",x)
R • 1.5k views
ADD COMMENT
1
Entering edit mode

It seems you deleted your questions text. You should not do that, as now other people with the same question as yours will not find the answers from which you benefited, and also makes a mess on this forum.

ADD REPLY
0
Entering edit mode

I didn't delete my question. Maybe when I sent my reply I put it in the same question box that's why the question is deleted. I will post the question again.

ADD REPLY
0
Entering edit mode

Use comments to reply, edit your question just to correct mistakes or provide additional information if needed. Thanks for reposting the question.

ADD REPLY
0
Entering edit mode

http://perldoc.perl.org/perlre.html#Regular-Expressions I'd suggest looking at some regex guides. The question is not appropriate for this forum, I'd suggest you try StackOverflow for future general cs queries.

ADD REPLY
4
Entering edit mode
9.0 years ago

This https://regex101.com/ could be also a better place to check and to learn, as it explain every part of the regular expression

("-__-|\\+__\\+","+",x)/
  • 1st Capturing group ("-__-|\\+__\\+","+",x)
    • 1st Alternative: "-__-
      • "-__- matches the characters "-__- literally
    • 2nd Alternative: \\+__\\+","+",x
      • ",x matches the characters ",x literally (case sensitive)
      • "+ matches the characters " literally
        • Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
      • ", matches the characters ", literally
      • \\+ matches the character \ literally
        • Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
      • __ matches the characters __ literally
      • \\+ matches the character \ literally
        • Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]

MATCH INFORMATION

ADD COMMENT
0
Entering edit mode

Thanks a lot Antonio for helping me.

ADD REPLY

Login before adding your answer.

Traffic: 2472 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6