- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 Convert Perl Compatible Regular Expressions (PCRE) into Lua
A regular expression is a special text string that is used to describe a search pattern.
PCRE (Perl Compatible Regular Expressions) is a C library implementing regex. It was written in 1997 when Perl was the de-facto choice for complex text processing tasks. The syntax for patterns used in PCRE closely resembles Perl. If you want to learn about PERL and its use cases, you should visit this link.
Now, let's take an example to see how to convert a PCRE into Lua and then print it.
Example
Consider the code shown below −
"\002\003\004\005\006\007\008\009\010\011\012\
”
The above string acts as a PCRE and we will convert it into a Lua string with the help of Lua string library functions and a regex.
The regex will look something like this −
"[\002-\009\011-\026\#?`(){}%[%]^*<>=~|; \"!$&'\130-\255])", "\%1"
Example
The code for converting the above PCRE into Lua string is shown below −
local a = "\002\003\004\005\006\007\008\009\010\011\012\
" res, _ = a:gsub("([\002-\009\011-\026\#?`(){}%[%]^*<>=~|; \"!$&'\130-\255])", "\%1") res, _ = res:gsub("
", "'
'") print(res)
Output
\\\\\\\\' '\\\' '
- Related Articles
- How to convert the finite automata into regular expressions?
- How to compare regular expressions in Perl and Python?
- How to convert JSON string into Lua table?
- How to use regular expressions with TestNG?
- JavaScript Regular Expressions
- Lua pattern matching vs regular expression
- How to use regular expressions in a CSS locator?
- How to match whitespace in python using regular expressions
- Java Regular Expressions Tutorial
- What is Regular Expressions?
- How to convert a string to int in Lua programming?
- How to split a string using regular expressions in C#?
- How to extract numbers from a string using regular expressions?
- How to validate an email address using Java regular expressions.
- How to make Format ABC-1234 in JavaScript regular Expressions?
