String.match confusion?

● ARCHIVED · READ-ONLY
Started by Isabella Ava 14 posts View original ↗
  1. Hi guys, i having a confusion about how string.match() function work.
    I saw inside of Yanfly item core, he check for a <TEXT COLOR: x> note match like this:
    line.match(/<(?:TEXT COLOR):[ ](\d+)>/i)
    but why ?:
    it should work without ?: but why did he include it?
    if it for checking zero or one of : shouldn't he wrote :? instead?
  2. ? means 0 or 1. And : is an empty symbol. Yanfly uses it to allow people to type it in any way among:
    <text color: 5>, < text color: 5>, <text color:5> or < text color:5>.
  3. Thanks @Poryg i didn't know that : is an empty symbol : E
  4. It's not mentioned in too many places, took me a bit to find it myself :D
  5. Wow that true. I had read on w3school & searched google but it didn't mention about this.
    That's weird : | oh right, there is something more that trouble me that i want to ask @Poryg
    Why match(/<C/i) didn't work?
    I mean i have this str = <CT>
    i tried str.match(/</i) and str.match(/CT/i) - both worked
    but when i tried /<C/i or /<CT>/i it returned nothing. : |
    do you know why?
  6. Perhaps < is a code as well? Try <:C if you want. I have seriously no idea though :D
  7. <:C didn't return anything too though. : | maybe you're right. No one mentioned about this :|
  8. Tried both in Ruby and JS, both works though.
    Screenshot_202.jpg
  9. in that case maybe she has it wrong somehow :D
  10. @Isabella Ava you tested it in a browser which read HTML tag. So, of course, an incomplete tag like '<' with missing '>' as end can't show up. Even if it's complete <CT> you couldn't even show it in the browser because the tag is unknown.

    I usually use https://repl.it/ to test stuff
  11. No, it doesn't have a problem. <> are html tags, while just < is not.

    Edit: Ninja'd :D

    try alert(res). You'll see it shows.
  12. Thanks @TheoAllen and @Poryg
    Well that's totally unexpected : ) (turn out that Editor read HTML tag sigh)
  13. The ?: means the group inside bracket ( ) won't be captured, so the first element in returned match in your example (ignore the match[0] is the whole string) will be the number