Advertisement:
GCWebhosting

Author Topic: What regex would I need to test this string?  (Read 1903 times)

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,143
  • Gender: Male
    • i30 Owners Club
What regex would I need to test this string?
« on: August 18, 2018, 03:53:48 PM »
Disclaimer: I know the square root of sod all about regular expressions and no amount of searching seems to change that  :-X

Ok, so I have several edits to the Tapatalk code to change the way it works in my forum.

One of the many changes I've made has been to detect and remove the signature applied by the Tapatalk plugin.

I've been using this to great effect so far

Code: [Select]
$_POST['message'] = preg_replace("/Sent from my (\S*) using Tapatalk/", '', $_POST['message']);
This works a treat as it allows me to detect and remove text such as

Code: (examples that work) [Select]
Sent from my XT108 using Tapatalk
Sent from my CDL-229 using Tapatalk

However it will not detect where the incoming string contains multiple components, such as:

Code: (these aren't detected) [Select]
Sent from my Samsung FunFone using Tapatalk
Sent from my XT560 CCD using Tapatalk


Any regexperts in the house able to assist?

Cheers

Offline SychO

  • Lead Customizer
  • Sophist Member
  • *
  • Posts: 1,390
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: What regex would I need to test this string?
« Reply #1 on: August 18, 2018, 04:10:25 PM »
that's because \S doesn't catch white spaces specifically, this works better
Code: [Select]
/Sent from my (.*) using Tapatalk/

Imazighen

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,143
  • Gender: Male
    • i30 Owners Club
Re: What regex would I need to test this string?
« Reply #2 on: August 18, 2018, 04:14:55 PM »
Works a treat!

Thanks buddy.