in reply to Fine tuning a reg exp

\w includes [a-zA-Z] (and others) so [A-Z \w] is exactly the same as [ \w] and certainly matches a-z.

- tye        

Replies are listed 'Best First'.
Re^2: Fine tuning a reg exp (\w)
by markjrouse (Initiate) on Feb 23, 2012 at 15:34 UTC
    Thanks, still learning reg exps. Even if I do this:
    ^([A-Z]+\s[A-Z]+,)
    I still get lowercase characters:
    ABU BAKR Sabaqah School
      I don't get that output with your regex:
      use warnings; use strict; while (<DATA>) { print if /^([A-Z]+\s[A-Z]+,)/; } __DATA__ ABU BAKR, Ibrahim Ali Muhammad (a.k.a. AL-LIBI, Abd al-Muhsin) (individual) [SDGT] AFGHAN SUPPORT COMMITTEE (ASC) (a.k.a. AHYA UL TURAS; a.k.a. JAMIAT AYAT-UR-RHAS AL ISLAMIA; a.k.a. JAMIAT IHYA UL TURATH AL ISLAMIA; a.k.a. LAJNAT UL MASA EIDATUL AFGHANIA) Grand Trunk Road, near Pushtoon Garhi Pabbi, Peshawar, Pakistan; Cheprahar Hadda, Mia Omar Sabaqah School, Jalalabad, Afghanistan [SDGT]

      prints:

      ABU BAKR, Ibrahim Ali Muhammad (a.k.a. AL-LIBI, Abd al-Muhsin)

      See http://sscce.org

      Since the regex you show will not match any lowercase letters and requires a comma and the match you show contains lowercase letters and no comma, I'm pretty sure you are not running the code you think you are (or similar mistake).

      - tye        

      Try posting your complete regex from "s" through ";" (e.g. s/([ A-Z]+)/myreplacement/gixm; -- it will make it clear what you're actually applying.

      Even better, post a small chunk of runnable code. It sounds from previous posts that you're just reading in lines and processing them in a pretty straightforward way, so the code should be quite short.

      A couple hours with a regex tutorial would also help you get going faster- the questions you're posting are chapter 1 or 2 kind of things, because they're almost the first thing everyone wants to do.

      Negative.
      perl -e 'print "Sabaqah School," =~ /^([A-Z]+\s[A-Z]+),/ ? "Yes" : "No +"' No