
Search hyphenated words
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Search hyphenated words
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 

--
Thanks
Shalu S
Thanks
Shalu S
Re: Search hyphenated words
Hi Shalu,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.
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" )
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.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
how regular expression are used in livecode
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
Thanks
Shalu S
Re: how regular expression are used in livecode
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
Thanks
Shalu S
Re: Search hyphenated words
Hi shalu,
beginner or not, do NOT open two threads for the same problem!
I merged these two threads!
Best
Klaus
beginner or not, do NOT open two threads for the same problem!
I merged these two threads!
Best
Klaus
Re: Search hyphenated words
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:
That sort of thing.
Craig Newman
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
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Search hyphenated words
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:
...and then put this in a button:
...you'll get:
2
5
For example, if you put this in a field:
Code: Select all
usa-CA, us-ca,something
Code: Select all
on mouseUp
put the number of words of fld 1 \
&cr& the number of trueWords of fld 1
end mouseUp
2
5
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Search hyphenated words
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
Is that correct shalu?
Pete
Re: Search hyphenated words
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:
But I suspect there is more to this...
Craig
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
Craig