Hi, have you try with (World>>Help>>Help Browser>>Regular Expressions Framework>>Usage)
SUBEXPRESSION MATCHES After a successful match attempt, you can query the specifics of which part of the original string has matched which part of the whole expression. A subexpression is a parenthesized part of a regular expression, or the whole expression. When a regular expression is compiled, its subexpressions are assigned indices starting from 1, depth-first, left-to-right. For example, `((ab)+(c|d))?ef' includes the following subexpressions with these indices: 1: ((ab)+(c|d))?ef 2: (ab)+(c|d) 3: ab 4: c|d After a successful match, the matcher can report what part of the original string matched what subexpression. And theres an example This facility provides a convenient way of extracting parts of input strings of complex format. For example, the following piece of code uses the 'MMM DD, YYYY' date format recognizer example from the `Syntax' section to convert a date to a three-element array with year, month, and day strings (you can select and evaluate it right here): | matcher | matcher := RxMatcher forString: '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+(:isDigit::isDigit:?)[ ]*,[ ]*(19|20)(:isDigit::isDigit:)'. (matcher matches: 'Aug 6, 1996') ifTrue: [Array with: (matcher subexpression: 5) with: (matcher subexpression: 2) with: (matcher subexpression: 3)] ifFalse: ['no match'] (should answer ` #('96' 'Aug' '6')'). you could make two subexpressions '([\s.;\:!?]*)(#\w+)' first subexpression is ([\s.;\:!?]*) and second subexpression is (#\w+) and then use It understandards these messages: subexpressionCount Answers the total number of subexpressions: the highest value that can be used as a subexpression index with this matcher. This value is available immediately after initialization and never changes. subexpression: anIndex An index must be a valid subexpression index, and this message must be sent only after a successful match attempt. The method answers a substring of the original string the corresponding subexpression has matched to. On Mon, Aug 8, 2016 at 7:10 PM, Casimiro - GMAIL <casimiro.barr...@gmail.com > wrote: > If someone can help me... I'm dealing with the following situation: > > > I may have a string in which matches of the following regex: > '[\s.;\:!?]*#\w+' may happen (multiple times). I want to replace the > #\w+ part of it by nothing but keep the [\s.;\:!?]* but it seems to be > no easy way using copyWithRegex: matchesTranslatedWith: or > copyWithRegex: matchesReplacedWith: > > Someone knows an easy (meaning, no several operations, etc) to do this???? > > > Thanks in advance, > > > Casimiro Barreto > > > -- > The information contained in this message is confidential and intended > to the recipients specified in the headers. If you received this message > by error, notify the sender immediately. The unauthorized use, > disclosure, copy or alteration of this message are strictly forbidden > and subjected to civil and criminal sanctions. > > == > > > --- > Este email foi escaneado pelo Avast antivĂrus. > https://www.avast.com/antivirus > > > -- Bernardo E.C. Sent from a cheap desktop computer in South America.