Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Regular expression
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Possessive matching=== In Java and Python 3.11+,<ref>[https://github.com/python/cpython/issues/34627/ SRE: Atomic Grouping (?>...) is not supported #34627]</ref> quantifiers may be made ''possessive'' by appending a plus sign, which disables backing off (in a backtracking engine), even if doing so would allow the overall match to succeed:<ref name=es-re>{{cite web |title=Essential classes: Regular Expressions: Quantifiers: Differences Among Greedy, Reluctant, and Possessive Quantifiers |url=https://docs.oracle.com/javase/tutorial/essential/regex/quant.html#difs |website=The Java Tutorials |publisher=[[Oracle Corporation|Oracle]] |access-date=23 December 2016 |archive-date=7 October 2020 |archive-url=https://web.archive.org/web/20201007183203/https://docs.oracle.com/javase/tutorial/essential/regex/quant.html#difs |url-status=live}}</ref> While the regex <code>".*"</code> applied to the string "Ganymede," he continued, "is the largest moon in the Solar System." matches the entire line, the regex <code>".*+"</code> does {{em|not match at all}}, because <code>.*+</code> consumes the entire input, including the final <code>"</code>. Thus, possessive quantifiers are most useful with negated character classes, e.g. <code>"[^"]*+"</code>, which matches <code>"Ganymede,"</code> when applied to the same string. Another common extension serving the same function is atomic grouping, which disables backtracking for a parenthesized group. The typical syntax is {{mono|1=(?>group)}}. For example, while {{mono|1=^(wi{{!}}w)i$}} matches both {{mono|wi}} and {{mono|wii}}, {{mono|1=^(?>wi{{!}}w)i$}} only matches {{mono|wii}} because the engine is forbidden from backtracking and so cannot try setting the group to "w" after matching "wi".<ref>{{cite web |title=Atomic Grouping |url=https://www.regular-expressions.info/atomic.html |website=Regex Tutorial |access-date=24 November 2019 |archive-date=7 October 2020 |archive-url=https://web.archive.org/web/20201007183204/https://www.regular-expressions.info/atomic.html |url-status=live}}</ref> Possessive quantifiers are easier to implement than greedy and lazy quantifiers, and are typically more efficient at runtime.<ref name=es-re/>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Regular expression
(section)
Add topic