Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Case Insensitive Regular Expressions

    Hi,
    Can somebody please help me create a case insensitive regular expression match? I've looked on the forum and elsewhere and can't figure it out. Some websites have suggested using PERL techniques such as \i or (?i), but I don't think I'm using them correctly and continue to get errors. I've listed my expression matching below, and have just been using [aA] to accomplish case insensitivity, but there must be a quicker way. Thanks!​

    Code:
    generate long_description_Malaria = regexm(Long_Description, ".*[Mm][Aa][Ll][Aa][Rr][Ii][Aa].*")
    Clay Bavinger
    University of Michigan

  • #2
    Does this work for you?

    Code:
    generate long_description_Malaria = regexm(lower(Long_Description), ".malaria.*")
    Regards, Mike


    Comment


    • #3
      Let me add that apparently the authoritative documentation for the regular expressions supported by Stata is not to be found or linked to in the online help or the manuals, but rather in this FAQ which can be found using search regular expression from within Stata. From that FAQ, you'll see that Stata provides very limited regular expression support that, alas, does not include the cited Perl constructs.

      Also, it is possible to accomplish the sample search (which I recognize may have been a simplified example) without using regular expressions using something like the following.

      Code:
      generate long_description_Malaria = strpos(lower(Long_Description),"malaria")>0

      Comment


      • #4
        Thank you both! Both of these approaches work perfectly.

        Comment


        • #5
          Above I wrote
          Let me add that apparently the authoritative documentation for the regular expressions supported by Stata is not to be found or linked to in the online help or the manuals, but rather in this FAQ which can be found using search regular expression from within Stata. From that FAQ, you'll see that Stata provides very limited regular expression support that, alas, does not include the cited Perl constructs.
          I later learned that this FAQ is out of date and does not reflect the subsequently enhanced capabilities of Stata regular expressions. See here for more on documentation of regular expressions as implemented in Stata.

          Comment

          Working...
          X