Announcement

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

  • Fractions in regular expressions

    I have some local government data with addresses that use the 1/2 character, e.g. "305 ½ SMITH RD " or "41½ JONES RD". I'm trying to extract the full numeric portion including the fraction, but in my search the only examples I've come across use fractions written like 1/2. Any suggestions?

  • #2
    Show us some examples using dataex.

    Comment


    • #3
      Consider this example and solution (this allows for fractions other than half as well):

      Code:
      clear
      input str40 address
      "305 ½ SMITH RD"
      "41½ JONES RD"
      "Platform 9¾, King's Cross Station"
      end
      
      gen wanted = ustrtrim(ustrregexs(1)) if ustrregexm(address, "([\d\s\x{00BC}-\x{00BE}\x{2150}-\x{215E}]+)")
      which produces:

      Code:
      . list, noobs string(40)
      
        +--------------------------------------------+
        |                           address   wanted |
        |--------------------------------------------|
        |                    305 ½ SMITH RD    305 ½ |
        |                      41½ JONES RD      41½ |
        | Platform 9¾, King's Cross Station       9¾ |
        +--------------------------------------------+
      Last edited by Hemanshu Kumar; 10 Jun 2023, 22:45.

      Comment


      • #4
        That worked, thank you Hemanshu!

        Comment

        Working...
        X