Need help pattern matching

Darmir
Posts: 226
Joined: Sun May 01, 2011 6:51 pm
Contact:

Need help pattern matching

Post by Darmir »

I am trying to figure out how to get the following to match all instances of words.
Code: [show] | [select all] lua
  general               packaging             general-labor       
  general-food          timberwright-scout    timberwright        
  farming-general       farming-field         farming-processing  
  general-cleaning      orcharding            shepherd            
  construction          woodcraft-recreation  recreation          
  athletics             fletching             gardening           
  general-fire          general-serving       general-recreation  
  laborers              leathercraft          leathercraft-dyed   
  siegecraft            study                 tanning             
  timberwright-cut      timberwright-plane    training            
  woodcraft             woodcraft-weapons     yrch-general        
  yrch-woodcraft  
I have the following pattern but I can't figure out how to also get it to match the last line which may have one to three words.
Code: [show] | [select all] lua
(\s+)([a-z0-9_-]+)(\s+)([a-z0-9_-]+)(\s+)([a-z0-9_-]+)

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Need help pattern matching

Post by Yetzederixx »

^\s+([\w-]+)\s+([\w-]+)\s+([\w-]+)$

Try that instead (\w covers everthing except the -). I'm not certain if you really want to capture the white space or not so I didn't bother surrounding it with (), change as necessary. Also, check the end of line and adjust or remove the $ as necessary.
Last edited by Yetzederixx on Mon May 02, 2011 3:15 pm, edited 1 time in total.

Darmir
Posts: 226
Joined: Sun May 01, 2011 6:51 pm
Contact:

Re: Need help pattern matching

Post by Darmir »

I need to capture the entire word like general-cleaning. Also that won't work for just one word on a line or two words.

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Need help pattern matching

Post by Yetzederixx »

You needed to be more specific then since your example contained three words on every line.

Code: Select all

^\s+([\w-]+)(?:\s+([\w-]+))?(?:\s+([\w-]+))?$
With that you'll have to test the existence of matches[3] and matches[4] to see if there's data to be collected. Check out this link for other help and regex testing: regexpal.com

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Need help pattern matching

Post by Yetzederixx »

Also, you will need to pay close attention to the end of the line. When I cut and pasted from your example, which I assume you got from your MUD, there was extra white space at the end. Simply adding a \s+ inbetween the last ? and the $ will do it if necessary, or a \s* will account for none-tons but I try to keep my regex's as specific as possible.

This would also be a prime example for one that needed to be shielded as well. Is there some pre-text which is always the same prior to the generation of the list? If not, you may wish to make an alias for this command and have its code enable the trigger and then code at the end of the trigger to disable it.

Darmir
Posts: 226
Joined: Sun May 01, 2011 6:51 pm
Contact:

Re: Need help pattern matching

Post by Darmir »

You needed to be more specific then since your example contained three words on every line.
If you look at the example the last line is one word. ie yrch-woodcraft
Is there some pre-text which is always the same prior to the generation of the list?
Yes there is pre-text.
The text is:
Code: [show] | [select all] lua
You currently have crafts in the following areas:
I am trying to add the words to a table then change them to a mxp link. I am following the example of the data capture video and the data isn't being put into the table.

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Need help pattern matching

Post by Yetzederixx »

Afraid mxp is over my head.

Set up a trigger with an exact copy of your pre-text, and have it turn on the child trigger
Make the combo box read 'begin of line substring'
Change the fire length to 100 or something
Make a new child trigger with the above pattern
Drag that trigger onto the pre-text one which will be it's parent or shield
Create a new child trigger to somehow match the yrch-woodcraft (make it more generic) and have it turn off the above child trigger

That's trigger shielding in a nutshell.
Attachments
Screen shot of a trigger shield
Screen shot of a trigger shield
trigger shield.png (59.08 KiB) Viewed 6537 times

Darmir
Posts: 226
Joined: Sun May 01, 2011 6:51 pm
Contact:

Re: Need help pattern matching

Post by Darmir »

Thanks for the help on this.
Now I got my pattern working and I am turning the list of crafts to links. They all highlight correctly when I test the pattern matching but two values do not change into click-able links.
Craft List.xml.xml
Beginning of SOI Craft Helper script
(4.99 KiB) Downloaded 303 times
Here is a screen shot. The first one is with the high-light turned on. The second is turned off. Not sure why it isn't matching those two words.
Image

Using version: Mudlet 2.0-rc3
Also how come my commands are not showing on the same line as the prompt?
Last edited by Darmir on Tue May 03, 2011 8:59 pm, edited 1 time in total.

Darmir
Posts: 226
Joined: Sun May 01, 2011 6:51 pm
Contact:

Re: Need help pattern matching

Post by Darmir »

Really weird thing is I just closed down mudlet restarted and connected to my mud to test the trigger and now two other words aren't being changed. They are not even from the same match before is was just doing in matches[4]. Now it is matches[3] and matches[4]

Below is the debug file of the text. In the debug is shows that it should have made them a link and colored.
debug.txt
Debug output
(11.1 KiB) Downloaded 329 times
Last edited by Darmir on Tue May 03, 2011 10:20 pm, edited 1 time in total.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Need help pattern matching

Post by Heiko »

You are using selectString( a, 1 ) which means that you select the first occurance of this substring within the line - and in your example you need the first and the second and possibly even more. Check the return value of the function and use the second parameter to select further matches on the same line if there are any (-> return value) e.g. selectString("timberwright",2) would fix your first problem.
Also look into selectCaptureGroup(). This function is more convenient.

Post Reply