[Solved] looking for regex for name age gender with mandatory spaces in between [closed]


First of all, let’s see what it is going to be matched by the pattern you mentioned:

=====================================================================
^[a-zA-Z]+(([\'\ \][(^10$|^[0-9]{1,2}]))+(([\'\ \][(?:m|M|f|F|)$]))*$
=====================================================================

Assert position at the beginning of the string «^»
Match a single character present in the list below «[a-zA-Z]+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
   A character in the range between “a” and “z” «a-z»
   A character in the range between “A” and “Z” «A-Z»
Match the regular expression below and capture its match into backreference number 1 «(([\'\ \][(^10$|^[0-9]{1,2}]))+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
   Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «+»
   Match the regular expression below and capture its match into backreference number 2 «([\'\ \][(^10$|^[0-9]{1,2}])»
      Match a single character present in the list below «[\'\ \][(^10$|^[0-9]{1,2}»
         Between one and 2 times, as many times as possible, giving back as needed (greedy) «{1,2}»
         A ' character «\'»
         A   character «\ »
         A ] character «\]»
         One of the characters “[(^10$|” «[(^10$|^[»
         A character in the range between “0” and “9” «0-9»
      Match the character “]” literally «]»
Match the regular expression below and capture its match into backreference number 3 «(([\'\ \][(?:m|M|f|F|)$]))*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
   Match the regular expression below and capture its match into backreference number 4 «([\'\ \][(?:m|M|f|F|)$])»
      Match a single character present in the list below «[\'\ \][(?:m|M|f|F|)$]»
         A ' character «\'»
         A   character «\ »
         A ] character «\]»
         One of the characters “[(?:m|MfF)$” «[(?:m|M|f|F|)$»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»

And it is very clear that this pattern would like to match context like:

aaaa' ]'m

And as you’re going to match something like Bob 33 M then most simplest pattern would be:

  (?i)^[a-z]+ [0-9]+ [mf]+$

which means

"(?i)" &     ' Match the remainder of the regex with the options: case insensitive (i)
"^" &        ' Assert position at the beginning of the string
"[a-z]" &    ' Match a single character in the range between “a” and “z”
   "+" &        ' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
"\ " &       ' Match the character “ ” literally
"[0-9]" &    ' Match a single character in the range between “0” and “9”
   "+" &        ' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
"\ " &       ' Match the character “ ” literally
"[mf]" &     ' Match a single character present in the list “mf”
   "+" &        ' Between one and unlimited times, as many times as possible, giving back as needed (greedy)
"$"          ' Assert position at the end of the string (or before the line break at the end of the string, if any)

Hope this link could help you to understand the subject.

4

solved looking for regex for name age gender with mandatory spaces in between [closed]