Message Boards Message Boards

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

Help with PatternSequence

Posted 10 years ago

I have a list of strings of the form

list={str1,str2,strx,str3,...,str10}

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:

{str1,{str2,strx},...,str10}

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

How about this:

lines //. {bef___, x_String, m_String /; StringFreeQ[m, DigitCharacter], 
    aft___} :> {bef, temp[x, m], aft} /. temp -> List
POSTED BY: Gianluca Gorni

Try

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

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract