Message Boards Message Boards

2 Replies
0 Total Likes
View groups...
Share this post:

Help with PatternSequence

Posted 9 years ago

I have a list of strings of the form


each string contains both letters and numbers, except for strx which does not contain numbers, what I want to do is attach strx to the element that immediately precedes it:


I am using

 lines /. {bef___, PatternSequence[x_, m_] /; 
  StringFreeQ[m, DigitCharacter], aft___} :> {bef, {x, m}, aft}

However this seems to match only the first occurrence of the pattern. How can I make it match several cases? I also want to be able to process a list that does not contain any of the strx.

POSTED BY: Miguel Olivo-V
2 Replies


list //. {bef,PatternSequence[x, m] /;StringQ[m] && StringFreeQ[m, DigitCharacter], aft} :> {bef, LIST[x, m], aft} /. LIST -> List

How about this:

lines //. {bef___, x_String, m_String /; StringFreeQ[m, DigitCharacter], 
    aft___} :> {bef, temp[x, m], aft} /. temp -> List
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract