Page 1 of 1

Regex to capture punctuation or space *Solved*

Posted: Sat Aug 08, 2020 12:15 am
by monki
So, I'm trying to grab "word**." or some punctuation or a space character, and not "some**word " I'm using "\S\*\*\W" as a search pattern to do this, which should work.

In Livecode "\S\*\*\W" will grab "years**." ending in period.
It will grab "mean**," ending in comma.
But it will not grab "someone** " ending in space.
And "\S\*\*\W" should select all of these.

But anything I try, that works in Expressions (regex tester) app or nvim, will not work in Livecode to regex a space character as an option along with punctuation. And as far as I know, back-references, which would make what I'm trying to do very easy, still isn't an option in Livecode.

Do I need to make another command that runs the same search but just focusing on the space character?

The issue was me, which I eventually figured out
The issue was that I kept parsing out the space character I was trying to find and replace :oops: Throwing it into an array by word would've done the same thing. But since I was now doing a replace on a known quantity, after I'd already replaced the unknown punctuation, I just ran a replace for "** " on the text as that was all that was left. Not too elegant, but it works. :wink:
Although I did make the "\S\*\*\W" work by chucking the text into an array by word and putting the "& space" back into the array keys. Worked fine for filtering and replacing, and let me get away with using the one handler to replace all closing tags.

Re: Regex to capture punctuation or space

Posted: Sat Aug 08, 2020 12:32 am
by monki
Ok, I've figured out the problem. In order to run a filter on the words of a text field, I "set the itemDel to space", which removed the space characters. So that was my issue. I'll have to look for a different solution, maybe an array, to filter the words.
monki wrote:
Sat Aug 08, 2020 12:15 am
So, I'm trying to grab "word**." or some punctuation or a space character, and not "some**word " I'm using "\S\*\*\W" as a search pattern to do this, which should work.

In Livecode "\S\*\*\W" will grab "years**." ending in period.
It will grab "mean**," ending in comma.
But it will not grab "someone** " ending in space.
And "\S\*\*\W" should select all of these.

But anything I try, that works in Expressions (regex tester) app or nvim, will not work in Livecode to regex a space character as an option along with punctuation. And as far as I know, back-references, which would make what I'm trying to do very easy, still isn't an option in Livecode.

Do I need to make another command that runs the same search but just focusing on the space character?

Any ideas on what I'm missing here?

Re: Regex to capture punctuation or space

Posted: Sat Aug 08, 2020 12:34 am
by FourthWorld
Instead of the word chunk, you can use trueWord. That parses according to the natural language rules in the IBM Unicode library, which are generally pretty good.

Re: Regex to capture punctuation or space

Posted: Sat Aug 08, 2020 12:50 am
by monki
FourthWorld wrote:
Sat Aug 08, 2020 12:34 am
Instead of the word chunk, you can use trueWord. That parses according to the natural language rules in the IBM Unicode library, which are generally pretty good.
The issue was that I kept parsing out the space character I was trying to find and replace :oops: Throwing it into an array by word would've done the same thing. But since I was now doing a replace on a known quantity, after I'd already replaced the unknown punctuation, I just ran a replace for "** " on the text as that was all that was left. Not too elegant, but it works. :wink:

Re: Regex to capture punctuation or space

Posted: Sat Aug 08, 2020 11:19 am
by stam
monki wrote:
Sat Aug 08, 2020 12:15 am
So, I'm trying to grab "word**." or some punctuation or a space character, and not "some**word " I'm using "\S\*\*\W" as a search pattern to do this, which should work.

In Livecode "\S\*\*\W" will grab "years**." ending in period.
It will grab "mean**," ending in comma.
But it will not grab "someone** " ending in space.
And "\S\*\*\W" should select all of these.

But anything I try, that works in Expressions (regex tester) app or nvim, will not work in Livecode to regex a space character as an option along with punctuation. And as far as I know, back-references, which would make what I'm trying to do very easy, still isn't an option in Livecode.

Do I need to make another command that runs the same search but just focusing on the space character?

Any ideas on what I'm missing here?
If i've understood correctly you want to grab a word that ends in 2 asterisks and a space?
On way to do this is

Code: Select all

\w+\*\*\s
seems to work on quick testing.

PS: I use RegExRx, an inexpensive app available on the appstore - great for constructing regular expressions, very well thought (even if it's made in LiveCode's main rival XOJO :))