Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Regular Expressions

It's been ages since I've had to ask for help here, but I've had to swallow my pride and come back begging for this one :D I'm writting an alternate message system, which autosizes itself. Each time the message text is changed, it uses a method to check the final width and height of the window. However, to do this it needs to eliminate the "\001" commands, as these are not displayed. However, I'm really stuck on the regexp to use:
The string to be removed would look like this: "\001"
However, none of these expressions produces a match:
/\00\d/ /\\00\d/ /\00[1-9]/
Could someone explain why? I'm not so good with regular expressions.
 

Jared

Member

The string "\001" sees the "\" as backslash-notation. So you have either write '\001' (also single-quoted string) or "\\001".

The regular expression /\\00\d/ would be correct. To erase a range of a string, use the slice! method.

string.slice!(/\\00\d/)
 
The string the message window uses is "\00n". Irritatingly, the expression /\001/ will match the string "\001", but /\00\d/ will not. I've been assuming that there is a particular significance to the format of the string "\001" and carried it over from the default message system, and it's only now that I've hit this hitch. I don't actually understand what the backslash is doing to cause the problem, and whether or not it's in the expression or the string, (or in fact both).
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top