Jump to content




Pattern help


  • You cannot reply to this topic
8 replies to this topic

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 November 2014 - 05:10 PM

I'm trying to make a lightweight format for crafting recipes. However, I've run into some trouble with the patterns, and I would appreciate advice here.

full code


example format

expected result vs result

I will continue to resolve this myself, however help is appreciated.

PS: I'm a bit annoyed by this, but the forum editor is inserting html end tags ('/>') in my code at random. Please ignore them, this code does not give me errors; it just doesn't work.

Edited by KingofGamesYami, 11 November 2014 - 05:57 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 11 November 2014 - 05:41 PM

^@ means "^@", [^@] means characters other than @.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 November 2014 - 05:50 PM

View PostLyqyd, on 11 November 2014 - 05:41 PM, said:

^@ means "^@", [^@] means characters other than @.

That fixed some of the problems, thanks. Still not working correctly, will update OP with details.

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 November 2014 - 07:11 PM

Update: Fixed more bugs, but still not working correctly
updated code

What I'm trying to get out of it is still in the OP, here'w what I'm currently getting

{
  [1]="minecraft:stone",
  [2]="minecraft:stone",
  [5]="minecraft:stone",
  [6]="none:none",
  [9]="minecraft:stone",
  [10]="minecraft:stone",
}


#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 November 2014 - 07:19 PM

Alright, one last thing to refine...
"([^:]+):([^:\r\n]+)&"
Works, but I have to change the pattern:
[[[email protected];[email protected];[email protected]
m:s&m:s&m:s&
m:s&n:n&m:s&
m:s&m:s&m:s&]]


#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 11 November 2014 - 08:30 PM

Protip: the /> artifact is related to emoticons, disabling emoticons in the post prevents its appearance.

Might try:

"([^:]+):([^&]+)&

If that doesn't work, try gmatching the individual fragments against the string and see what turns up.

#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 November 2014 - 08:40 PM

View PostLyqyd, on 11 November 2014 - 08:30 PM, said:

Protip: the /> artifact is related to emoticons, disabling emoticons in the post prevents its appearance.

How? I'm in plaintext editor.

View PostLyqyd, on 11 November 2014 - 08:30 PM, said:

Might try:

"([^:]+):(/>/>[^&]+)&

If that doesn't work, try gmatching the individual fragments against the string and see what turns up.

I'll see how that worked out, the problem was it wouldn't recognize the last part of the line because it was not followed by a &. I attempted using &?, but that made it recognize things incorrectly.

Edit Not related to the current code, but how would I go about finding the number of times a word is in the string, eg "minecraft"?

Edited by KingofGamesYami, 11 November 2014 - 08:47 PM.


#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 11 November 2014 - 10:18 PM

Use the full editor, it's a check box on the right.

You may just want to use something like this:

"(%w+):(%w+)"

As for the number of times, gmatch with the word as the pattern and a counter variable should work.

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 November 2014 - 11:55 PM

View PostLyqyd, on 11 November 2014 - 10:18 PM, said:

Use the full editor, it's a check box on the right.

You may just want to use something like this:

"(%w+):(/>%w+)"

As for the number of times, gmatch with the word as the pattern and a counter variable should work.

That worked.

I thought I'd probably have to resort to gmatch. Oh well...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users