- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to compare regular expressions in Perl and Python?
The most basic regex features are nearly the same in nearly every implementation: wild character ., quantifiers *, +, and ?, anchors ^ and $, character classes inside , and back references \1, \2, \3etc.
Alternation is denoted | in Perl and Python
Perl and Python will let you modify a regular expression with (?aimsx). For example, (?i) makes an expression case-insensitive. These modifiers have the same meaning on both languages. Also, both languages let you introduce a comment in a regular expression with (?# … ).
Perl and Python support positive and negative look-around with the same syntax: (?=), (?!), (?<=), and (?<!).
Both languages support the anchors \A and \Z, and the character classes \d and \D, \s and \S.
Both languages let you name a capture with (?P<name>) and reference it with (?P=name). Perl has its own syntax for this in addition to supporting the syntax of Python.
- Related Articles
- How to Convert Perl Compatible Regular Expressions (PCRE) into Lua
- How to match whitespace in python using regular expressions
- How do backslashes work in Python Regular Expressions?
- How to compare two strings in Perl?
- How to use regular expressions in css in Selenium with python?
- How to use regular expressions in xpath in Selenium with python?
- How to compare two arrays for equality in Perl?
- How to extract data from a string with Python Regular Expressions?
- How to match whitespace but not newlines using Python regular expressions?
- Extracting email addresses using regular expressions in Python
- How to use regular expressions with TestNG?
- How to use regular expressions in a CSS locator?
- Regular Expression Special Variables in Perl
- What is the groups() method in regular expressions in Python?