-
-
Notifications
You must be signed in to change notification settings - Fork 32k
re.sub is only replacing max. of 2 string found by regexp. #79724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Below are the logs: >>> dat = '"10GE" "4x" "AMPC" "B3" "BUILTIN" "DOWN" "LU" "SFP+" "ether" "xe" "DOWN" "MPC" "BUILTIN"'
>>> type = re.subn(r'\"BUILTIN\"|\"B\d\"|\"I\d\"|\"LU\"|\"Trinity\"|\"Trio\"|\"DOWN\"|\"UNKNOWN\"|'
... r'^AND$|\"Q\"|\"MPC\"|\"EA\d\"|\"3D\"', '', dat, re.I)
>>> type
('"10GE" "4x" "AMPC" "DOWN" "LU" "SFP+" "ether" "xe" "DOWN" "MPC" "BUILTIN"', 2)
>>> dat = '"10GE" "4x" "AMPC" "DOWN" "LU" "SFP+" "ether" "xe" "DOWN" "MPC" "BUILTIN"'
>>> type = re.subn(r'\"BUILTIN\"|\"B\d\"|\"I\d\"|\"LU\"|\"Trinity\"|\"Trio\"|\"DOWN\"|\"UNKNOWN\"|'
... r'^AND$|\"Q\"|\"MPC\"|\"EA\d\"|\"3D\"', '', dat, re.I)
>>> type
('"10GE" "4x" "AMPC" "SFP+" "ether" "xe" "DOWN" "MPC" "BUILTIN"', 2)
>>> dat = '"10GE" "4x" "AMPC" "SFP+" "ether" "xe" "DOWN" "MPC" "BUILTIN"'
>>> type = re.subn(r'\"BUILTIN\"|\"B\d\"|\"I\d\"|\"LU\"|\"Trinity\"|\"Trio\"|\"DOWN\"|\"UNKNOWN\"|'
... r'^AND$|\"Q\"|\"MPC\"|\"EA\d\"|\"3D\"', '', dat, re.I)
>>> type
('"10GE" "4x" "AMPC" "SFP+" "ether" "xe" "BUILTIN"', 2)
>>> dat = '"10GE" "4x" "AMPC" "SFP+" "ether" "xe" "BUILTIN"'
>>> type = re.subn(r'\"BUILTIN\"|\"B\d\"|\"I\d\"|\"LU\"|\"Trinity\"|\"Trio\"|\"DOWN\"|\"UNKNOWN\"|'
... r'^AND$|\"Q\"|\"MPC\"|\"EA\d\"|\"3D\"', '', dat, re.I)
>>> type
('"10GE" "4x" "AMPC" "SFP+" "ether" "xe" ', 1)
>>> |
The third argument of re.sub() is the maximal number of replacements. re.I == 2. sub(pattern, repl, string, count=0, flags=0)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the Match object and must return
a replacement string to be used. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: