Search hyphenated words

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
shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Search hyphenated words

Post by shalu » Tue Jun 23, 2015 8:23 am

I am a beginner in live code. I have a Scrolling field that contain lots of text I want to seach the hyphenated words eg (usa-uk,usa--uk,usa---uk ) if these type of words present in the scrolling filed then it should place another one scrolling field. is it possible :oops:
--
Thanks
Shalu S

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Search hyphenated words

Post by Thierry » Tue Jun 23, 2015 8:32 am

shalu wrote: I have a field that contain lots of text I want to seach the hyphenated words eg (usa-uk,usa--uk,usa---uk ) if these type of words present in the scrolling filed then it should place another one scrolling field.
Hi Shalu,

Here is a quick one for a start:

Code: Select all

   put "xxx, zzz, usa-uk,usa--uk,usa---uk,zzz" into T
   put replaceText( T, "usa-+uk", "USA_UK" )
You might find interesting to check in the dictionary:
replaceText(), matchChunk() and matchText().
They all works with regular expressions (regex)

Good luck,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

how regular expression are used in livecode

Post by shalu » Tue Jun 23, 2015 10:28 am

how regular expression are used in livecode. for eg I want to seacrch hyphenated words for that I am uses "\w\-\w" how I am uses this code
--
Thanks
Shalu S

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Re: how regular expression are used in livecode

Post by shalu » Tue Jun 23, 2015 11:01 am

Code: Select all

on mouseUp
   put the text of fld "SSS" into sha
   repeat for each word tLine in sha 
      put matchtext(tLine, "(\w\-\-\w)") into ssa
      if ssa is true then
         answer tLine
       
       answer ssa
          end if
   end repeat

end mouseUp
--
Thanks
Shalu S

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Search hyphenated words

Post by Klaus » Tue Jun 23, 2015 11:55 am

Hi shalu,

beginner or not, do NOT open two threads for the same problem!
I merged these two threads!


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Search hyphenated words

Post by dunbarx » Tue Jun 23, 2015 2:07 pm

Hi.

Regex is the basis for the power behind replaceText(), matchChunk() and matchText(), as Thierry mentioned. He is our regex guru.

But am I missing your question? Did you simply want to replace all instances of words that contain "-" with another character? Or to eliminate that hyphen from the text entirely? If so. why not just:

Code: Select all

put the text of fld "SSS" into sha
replace "-" with "_" in sha
--or
replace "-" with empty in sha
That sort of thing.

Craig Newman

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

Re: Search hyphenated words

Post by FourthWorld » Tue Jun 23, 2015 3:21 pm

If you're using LiveCode 7 try the "trueWord" chunk type rather than "word". The "word" chunk type uses the old-style rules, maintained in v7 for backward compatibility. But with v7's inclusion of the comprehensive Unicode libraries for smarter parsing, the "trueWord" chunk type allows us to to accommodate more natural-language expressions.

For example, if you put this in a field:

Code: Select all

usa-CA, us-ca,something
...and then put this in a button:

Code: Select all

on mouseUp
   put the number of words of fld 1 \
         &cr& the number of trueWords of fld 1
end mouseUp
...you'll get:

2
5
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Search hyphenated words

Post by phaworth » Tue Jun 23, 2015 7:31 pm

I think what shalu wants to do is put the hyphenated words into a different field, not sure if they need to be deleted from the original field or not.

Is that correct shalu?

Pete

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Search hyphenated words

Post by dunbarx » Tue Jun 23, 2015 9:37 pm

If what Pete is saying is true, then the problem goes away. Put this into a button script, with field 1 the field of interest, and a fld 2 to hold the extracted data:

Code: Select all

on mouseUp
   set the itemdel to "-"
   get fld 1
   repeat with y = 1 to the number of items of it
      put the last word of item y of it & "-" & the first word of item y + 1 of it & return after temp
   end repeat
   put temp into fld 2
end mouseUp
But I suspect there is more to this...

Craig

Post Reply