Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c1e12c

Browse files
committed
#25517: fix regex in the regex howto. Patch by Elena Oat.
1 parent d3d6c3e commit 4c1e12c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Doc/howto/regex.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,17 +1004,18 @@ confusing.
10041004

10051005
A negative lookahead cuts through all this confusion:
10061006

1007-
``.*[.](?!bat$).*$`` The negative lookahead means: if the expression ``bat``
1007+
``.*[.](?!bat$)[^.]*$`` The negative lookahead means: if the expression ``bat``
10081008
doesn't match at this point, try the rest of the pattern; if ``bat$`` does
10091009
match, the whole pattern will fail. The trailing ``$`` is required to ensure
10101010
that something like ``sample.batch``, where the extension only starts with
1011-
``bat``, will be allowed.
1011+
``bat``, will be allowed. The ``[^.]*`` makes sure that the pattern works
1012+
when there are multiple dots in the filename.
10121013

10131014
Excluding another filename extension is now easy; simply add it as an
10141015
alternative inside the assertion. The following pattern excludes filenames that
10151016
end in either ``bat`` or ``exe``:
10161017

1017-
``.*[.](?!bat$|exe$).*$``
1018+
``.*[.](?!bat$|exe$)[^.]*$``
10181019

10191020

10201021
Modifying Strings

0 commit comments

Comments
 (0)