Regex to capture punctuation or space *Solved*

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
monki
Posts: 59
Joined: Tue Dec 13, 2011 10:56 pm

Regex to capture punctuation or space *Solved*

Post by monki » 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?

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.
Last edited by monki on Sat Aug 08, 2020 5:39 pm, edited 2 times in total.

monki
Posts: 59
Joined: Tue Dec 13, 2011 10:56 pm

Re: Regex to capture punctuation or space

Post by monki » Sat Aug 08, 2020 12:32 am

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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Regex to capture punctuation or space

Post by FourthWorld » 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

monki
Posts: 59
Joined: Tue Dec 13, 2011 10:56 pm

Re: Regex to capture punctuation or space

Post by monki » Sat Aug 08, 2020 12:50 am

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:

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Regex to capture punctuation or space

Post by stam » Sat Aug 08, 2020 11:19 am

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 :))

Post Reply