How do I remove all special characters from a string?

0 favourites
  • 2 posts
From the Asset Store
A collection of various soldier character sprites for creating a 2D platformer or sidescroller game
  • I'm not familiar with Regex but I fear I may need to learn quickly for this. I was hoping I could accomplish this with replace(), another expression, or a feature of a text(input) box that disallows special characters.

    I know:

    replace(src, find, rep)

    Find all occurrences of find in src and replace them with rep.

    But can you have multiple options for find? With no success I tried:

    replace(Entry.Text, "/|?", "")

    replace(Entry.Text, "/"|"?", "")

    replace(Entry.Text, "/""?", "")

    replace(Entry.Text, "/"&"?", "")

    I know I could layer them:

    replace(replace(Entry.Text, "?", ""), "/", "")

    But that seems tedious if I need to do all special characters —> !@#$%^&*()_+-=[]{}|\;':",.<>/?

    Purpose is for passing text via AJAX to php file (to submit in mysql table). I remove special characters in the php script but want to avoid any errors in passing the values to the php script. I'm pretty sure that at least = ? & would disrupt the URL. I could research to narrow down eliminating only the ones that would disrupt but would rather be safe and eliminate them all ... as who really needs any of those special characters in their name.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Found a simple Regex example and modified, does this encompass everything I need:

    RegexReplace(Entry.Text, "\W", "g", "")

    I don't understand much Regex at all—most of the Regex examples/tutorials were over my head atm but— finally found a message board post that helped after sifting through a bunch I couldn't grasp.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)