views:

446

answers:

11

Hi All,

I'm writing a term paper on regular expressions and I'm a bit confused regarding the way one uses the word "match" when referring to regexes. Which of the following is the correct wording to use:

  • "The regular expression matches the string"

or

  • "The string matches the regular expression"

Or are they both correct? All opinions on this are welcome! I really want to get this right and I think it would help my understanding greatly to get this clarified.

+2  A: 

The latter sounds better to me. The regex specifies a pattern that the string may match. But there's nothing really wrong with either.

Paul Beckingham
+3  A: 

The string is being matched to the regular expression pattern, therefore I would say the latter is more accurate

Russ Cam
+9  A: 

I think both are correct. It depends on what you're focusing on. If your focus is in the regular expression itself to see if it serves to work on a given string or set of strings, then you use the first sentence. In the contrary, if you are more interested in looking at a set of strings that match certain criteria, the second one is applicable. You know, a match has the meaning of some equivalence under certain conditions, so both sentences sound equivalent to me.

Diego Sevilla
+1  A: 

If you said either one to me, I would understand what you're saying. I'm sure people have said both to me, and I never thought either one needed to be corrected.

Don Branson
A: 

I agree that the string matches (or not) the regular expression. To make it clear why I'd say: the regular expression defines a grammar, and a given string is either well-formed according to that grammar or not.

dwc
A: 

"The regular expression matches the string"
True if the RE matches the whole string (eg. using ^ $ or just happening to match everything). Otherwise, I would write: the regular expression has match(es) in the string.

"The string matches the regular expression"
Again, true if the regex matches everything, otherwise it sounds a bit odd.
But indeed, in the case of a whole match, the two sentences are equivalent.

PhiLho
+3  A: 

When two things match, it is (from a logical perspective at least) irrelevant in which order you mention them.

So it depends on what you want to put focus on.

The string matches the regular expression: Focus is on the string.

The regular expression matches the string: Focus is on the regex.

Tomalak
A: 

Since you're looking for a regular expression within a string, it's more correct to say that you've found the regular expression since that's a one-way relationship.

But as to which matches which, that's a two way relationship and it doesn't really matter (in English, anyway - I can't vouch for other languages ), so either would be correct.

My preference would be to say that the string matches the regular expression, since the RE is the invariant part and the string changes. But that's a personal preference and is unlikely to have any bearing on reality :-)

paxdiablo
A: 

"The string matches the regular expression" seems to be shorthand for "the string is in the language defined by and isomorphic to the regular expression."

"The regular expression matches the string" seems to be shorthand for "a parser automaton compiled from the regular expression will parse the string and halt in a final state."

Justice
A: 

I'd say:

At design time a user/develper creates a regular expression that matches a string.

At run time a regular expression engine finds a string that matches the regular expression.

(Not intended to be a definition, just an example of common usage.)

it depends
A: 

Since a regular expression represents a possibly infinite set of finite strings, I would say that it is most correct to write that "string s matches regular expression r". You could also say that "string s is member of the set generated by regular expression r".

Also, you should consider using the words accept and reject, especially if you intend to discuss finite automata in your paper.

splicer