24

I am mostly active on the various tags. I am also a "fan" of regular expressions (regex) and tend to enter questions to see if I can help or learn something new. I also like to curate the site where I can by editing and I sometimes get confused about how to tag those questions.

There is, of course, the widely used tag. But Python has its built-in library for dealing with regex, with its own tag - .

Now, is only tagged in 544 questions, while there are around 35k questions tagged with and .

The thing is, that questions about regex with Python are mostly using re (I doubt anyone implement their own Python regex engine...). How should I tag Python regex questions? Should I tag them with both re and regex, or just re to avoid cluttering the tags? Or alternatively just regex? The reject tag edit message (from the Suggested Edit review queue) states:

This edit introduces tags that do not help to define the topic of the question. Tags should help to describe what the question is about, not just what it contains.

*emphasis mine

According to this, one might say that re is part of what the question contains and regex already defines what the question is about. In that case, why do we even need the re tag?

4
  • 11
    IMO, it depends, if the post is about the regex itself, use regex, if the post is about how to use re, use re Commented Nov 17, 2020 at 10:24
  • 5
    There's also a tag for a 3rd party module python-regex called regex on pypi
    – Jon Clements Mod
    Commented Nov 17, 2020 at 13:40
  • 1
    "I doubt anyone implement their own Python regex engine" - why not? New libraries appears every day, e.g. json.net shouldn't be used for every json question. Don't tag everything with re! Also, there could be language-agnosic questions, so don't tag everything with python either.
    – Sinatr
    Commented Nov 17, 2020 at 14:56
  • 2
    They should be tagged with Python and Regex, of course. If it's about using Re to do it, also tag it with Re.
    – TylerH
    Commented Nov 17, 2020 at 16:51

2 Answers 2

14

Sentence #1 from https://stackoverflow.com/tags/regex/info:

Regular expressions provide a declarative language to match patterns within strings.

regex refers to the pattern used to find matches within a string. This is true regardless of language and is the most commonly requested aspect for assistance.

Using re to execute the regex is a different ballgame. Ditto for using python-regex for executing a regex pattern. I will focus on re for this answer.

If someone posts "How to enable the dotall flag?" or "How to loop all matches?" then python and re are technically all that's needed since we probably don't have to alter the regex expression itself (assuming it's correct, which it rarely is).

However if the question is "Pattern not working as expected" then python and regex are acceptable tags. If it turns out that the answer is "You need to turn on the dotall flag" then it is safe to add the re tag.

In contrast to PHP where you need to literally add /s to the regex string so one would not add a tag for preg_replace nor preg_match.

11
  • 1
    "How to loop all matches?" - why re tag for this? Typo?
    – Sinatr
    Commented Nov 17, 2020 at 15:00
  • 3
    @Sinatr No typo. To loop matches you need re.finditer() which is part of the re library. The for loop is a language construct in Python so no additional tags would be needed.
    – MonkeyZeus
    Commented Nov 17, 2020 at 15:04
  • 2
    Matches is regex term (so this tag make sense to add) and matches are returned for an input. If question is "How do I get results of my _insert_re_stuff_here", then it's re. "How to loop all matches" is likely language-agnostic regex-pattern question, though re would be neccessary if OP attempt is done using re.
    – Sinatr
    Commented Nov 17, 2020 at 15:10
  • 1
    @Sinatr How else would you suggest to do it in Python?
    – MonkeyZeus
    Commented Nov 17, 2020 at 15:30
  • 2
    [python][regex] - in general, if you accept answer using another python library too. [python][re] - implementation specific questions, you know the problem is not expression; to report bugs or query about library feature. [python][regex][re] - re-specific regex question (not allowed to use anything else). [regex] - language agnostic question. [regex][re] or just [re] - don't use, language tag is important, disregards re is python currently, it could change.
    – Sinatr
    Commented Nov 17, 2020 at 16:03
  • 2
    Thank you, that already clears up some confusion: pattern problems - regex ; functional problems - re/python-regex
    – Tomerikoo
    Commented Nov 17, 2020 at 16:30
  • @Sinatr Sure that sounds fine; good luck enforcing it. Most people asking regex questions have no clue if their problem is Python string interpolation, a library/function issue, iteration problem, or pattern issue so tagging with python and regex is the best way to ensure enough eyeballs land on the question; the other tags are after-thoughts.
    – MonkeyZeus
    Commented Nov 17, 2020 at 17:08
  • @Tomerikoo Glad I could help. Don't blindly update tags; you'd have to read each question individually and assess whether re is applicable.
    – MonkeyZeus
    Commented Nov 17, 2020 at 17:12
  • @MonkeyZeus Of course! That is always true and I follow it no worries. It's just that as a silly human-being it is always easier to have some rule-of-thumb to follow :)
    – Tomerikoo
    Commented Nov 17, 2020 at 17:19
  • I mean, there are cases where python + regex could be mapped to re in a formulaic way - basically anything with "variable width lookbehind/lookahead" is going to be an re issue - but then the answer will probably be python-regex anyway so . . .
    – Daniel F
    Commented Nov 18, 2020 at 9:33
  • 1
    @DanielF Why would a variable width lookahead require python-regex?
    – MonkeyZeus
    Commented Nov 18, 2020 at 12:33
5

There are also other kinds of regex "engines" available to Pythonistas, for example, https://pypi.org/project/regex/ which adds functionality above and beyond Python's re implementation. Those could be tagged + but not as differences are implementation dependent.

Unless you know for sure if the code uses re or regex - better not retag them.

If you need a pypi.regex and re - compatible regex you could even use both :D


I just saw the comment by Jon Clements - about there being a tag specifically for https://pypi.org/project/regex/.

1
  • Thanks Patrick. My question came up after recently encountering a question about regex in python simply tagged python. That got me confused on how would be best to add the regex part to the tags. I would usually not mess too much with tags that seem to already be relevant (regarding your remark about better not retag them)
    – Tomerikoo
    Commented Nov 17, 2020 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .