Anonymous user
Regular expressions: Difference between revisions
→{{header|Lua}}: Add note about Lua patterns vs. regular expressions, show some pattern syntax in example and substitution with match reference
m (→{{header|Python}}: PEP-8 whitespace, Python 3 compatibility) |
(→{{header|Lua}}: Add note about Lua patterns vs. regular expressions, show some pattern syntax in example and substitution with match reference) |
||
Line 891:
=={{header|Lua}}==
<lang lua>str1 = "This is a string!"▼
In Lua many string manipulation methods use ''patterns'', which offer almost the same fucntionality as regular expressions, but whose syntax differs slightly. The percent sign (<code>%</code>) is generally used instead of a backslash to start a character class or a reference for a match in a substitution.
pattern = ".*name is (%a*).*"
if test:match(pattern) then
print("Name found.")
end
sub, num_matches = test:gsub(pattern, "Hello, %1!")
print(sub)</lang>
=={{header|M4}}==
|