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.
Need help pattern matching
Need help pattern matching
I am trying to figure out how to get the following to match all instances of words.
-
- Posts: 186
- Joined: Sun Nov 14, 2010 5:57 am
Re: Need help pattern matching
^\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.
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.
Re: Need help pattern matching
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.
-
- Posts: 186
- Joined: Sun Nov 14, 2010 5:57 am
Re: Need help pattern matching
You needed to be more specific then since your example contained three words on every line.
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
Code: Select all
^\s+([\w-]+)(?:\s+([\w-]+))?(?:\s+([\w-]+))?$
-
- Posts: 186
- Joined: Sun Nov 14, 2010 5:57 am
Re: Need help pattern matching
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.
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.
Re: Need help pattern matching
If you look at the example the last line is one word. ie yrch-woodcraftYou needed to be more specific then since your example contained three words on every line.
Yes there is pre-text.Is there some pre-text which is always the same prior to the generation of the list?
The text is:
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.
-
- Posts: 186
- Joined: Sun Nov 14, 2010 5:57 am
Re: Need help pattern matching
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.
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
- trigger shield.png (59.08 KiB) Viewed 6542 times
Re: Need help pattern matching
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. 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.
Using version: Mudlet 2.0-rc3
Also how come my commands are not showing on the same line as the prompt?
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. 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.
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.
Re: Need help pattern matching
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.
Below is the debug file of the text. In the debug is shows that it should have made them a link and colored.
Last edited by Darmir on Tue May 03, 2011 10:20 pm, edited 1 time in total.
Re: Need help pattern matching
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.
Also look into selectCaptureGroup(). This function is more convenient.