Jump to content

Get alpha characters and stop when special character detected


gcue
 Share

Go to solution Solved by mikell,

Recommended Posts

Hi world

I am trying to get JNNR or JZU from these strings. 

$zip_file = "JNNR.zip"
$zip_file = "JZU-(excel).zip"

There can be different number of alpha characters and either in lower/uppercase.  I would like to stop when a special character is detected (in other words remove anything after a special character including a space is detected)

Here is what I've tried so far - feel like I'm getting close but cant seem to figure it out

$initials = StringRegExpReplace($zip_file, "([A-Z])\w+[^a-z0-9]*", "")

thank you in advance!

Link to comment
Share on other sites

1 hour ago, gcue said:

i am trying to understand the need for 2 brackets?

I'm sure @mikell can explain it much better ;). Anyway, have a look at the StringRegExp help (in particular : Character classes and POSIX classes).

The outer brackets represent a character class, which means a defined set of allowed/disallowed characters .  

The inner brackets represent a POSIX class, here [:alnum:]

So if you use a POSIX class within a character class ,the notation is  [[:alnum:]]

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

23 minutes ago, Musashi said:

I'm sure @mikell can explain it much better

No no it was absolutely perfekt - and pretty good for my laziness btw, so thank you  :)

The holy Help File says :
POSIX classes : These are named sets specifications to be used themselves within a character class
It says too (see "Anchors") :
the dollar matches at the end of the subject text, and also just before a newline sequence if option (?m) is active
o:)

Link to comment
Share on other sites

Shameless plug: the AutoIt regex help is there for you.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...