Announcement

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

  • How to use regular expressions to substract all matched strings?

    How to use regular expressions to substract all matched strings?
    More specifically, I want to generate two variables, one contains all strings begining with AA and ending with BB, the other contains all strings begining with BB and ending with AA
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str41 var1
    "AA: ……BB:……AA: ……BB:……AA:"
    end

  • #2
    I think you need to tell us more rules. If I look for the first pattern I find two matches and two other substrings. If I look for the second pattern I find two matches also, but to different substrings, and some junk.

    Here is how the first rule parses, for example.
    Code:
    AA: ……BB
    :……
    AA: ……BB
    :……AA:
    Last edited by Nick Cox; 15 Jul 2023, 03:10.

    Comment


    • #3
      Exactly, for beginning with AA ending with BB, I want to store the two matches as a variable, namely "First Third"
      Code:
       
       AA:First BB: Second AA: Third BB: Fourth AA:

      Comment


      • #4
        That doesn't resolve my uncertainty about what you want to do. Someone else may be able to help.

        Comment


        • #5
          If you think the colon make you misunderstood, that was my fault. Just drop the colon,
          Code:
           
           "AA……BB……AA……BB……AA"

          Comment

          Working...
          X