Rex

Stringregexp headach

23 posts in this topic

Hi I'm trying to split this sting "The.Last-Stalker-Lars-Ole.Kepler" with regexp

I need it to be splitted like this "The.Last-Stalker" "Lars-Ole.Kepler"

I have tried with this (?i)(.+)-(.+), and with this (?i)(.[^-]+)-(.+) and a couple other types like that, but it splits on either the one side or the other side of my expression :

Of course the string can change, all that i know for sure about the string is that it contains at least one "-" and the string should be splitted in to two as above.

Any one that could help me out, or point me in the correct direction of how to do this.

Cheers

/Rex

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Rex,

The problem will be to clearly define the "-" on which to split the string - the problem is trivial if you have only the one but a unique solution is probably not possible when there are several such characters as in your example. Can you be a bit more precise in defining where the split point occurs? :huh:

M23

Edited by Melba23
Wrong button, too soon!

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

This (Regular Expressions: The Complete Tutorial) might be useful for future reference :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

@Melba23

Yea I was affright of that :( how ever i know that the string continues like this "Unknown-string".BookRead-2015

And yes i should had posted that in my first tread, sry for that :> also I should had postede the entire regexp witch is (?i)(.+)-(.+).BookRead-2015 :mad2:

@TheDcoder

I have read the Tut several times, but didn't seem to find a solution in it :

Cheers

/Rex

Share this post


Link to post
Share on other sites

Well, not sure to really understand... You shoud give more examples with the expected result.

You can still try with this :

#Include <Array.au3>

$sString = "The.Last-Stalker-Lars-Ole.Kepler"

$aResult = StringRegExp($sString, "(?i)([a-z.]+-[a-z.]+)", 3)

_ArrayDisplay($aResult)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

/Rex

 

I have been the other day learning and fighting with RegularExpressions because i thought was an improvement to my program strings treatament. After some sort of hard-hell learningcurve i reached to take that i needed. Then i realised (plus a bit dangerous of recursive loops, and long implement time) that the performance was worse than before with some snnipets i had native-Autoit based.

So i throwed all RegExp code to the trash (i know there are times can be the best/only option), and i dont think i´ll retake it again because by now i managed to reach without them. Its too hard to me, with no speed win.

If you are interested in alternative way to regexp, i could help you.

Edited by zalomalo

My english shucks, i know it.

Share this post


Link to post
Share on other sites

@zalomalo

Thx for the offer, any way this can be done, is welcome

Cheers

/Rex

Share this post


Link to post
Share on other sites

On a string like this  "one.two-three-four-five.six"  if the results may be
"one.two"
"one.two-three"
"one.two-three-four"
"one.two-three-four-five"
Then unless you introduce some more restrictions/requirements as Melba suggested, it will not be possible to find a working generic regular expression simply because regex can't guess the expected result
 

Share this post


Link to post
Share on other sites

@Rex Sorry for for late reply but you can learn regex from this (Expresso) tool, It also has a regex builder :)!


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

On a string like this  "one.two-three-four-five.six"  if the results may be

"one.two"

"one.two-three"

"one.two-three-four"

"one.two-three-four-five"

Then unless you introduce some more restrictions/requirements as Melba suggested, it will not be possible to find a working generic regular expression simply because regex can't guess the expected result

 

I know, but thats all the info I have - that also why I wrote Regexp Headach ;)

Cheers

/Rex

Share this post


Link to post
Share on other sites

@Rex Sorry for for late reply but you can learn regex from this (Expresso) tool, It also has a regex builder :)!

Wauuuu that so coool, I will play with it later, thx so much :)

Cheers

/Rex

Share this post


Link to post
Share on other sites

@Rex Welcome :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Rex,

Is the form of the string you want to capture always the same,  Xn.Xn-Xn or Xn-Xn.Xn ?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Rex,

Is the form of the string you want to capture always the same,  Xn.Xn-Xn or Xn-Xn.Xn ?

kylomas

The string will always contain one "-", thats all I know for shure :/

/Rex

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

RegExp are abstract operations with strings, and yo dont have a trouble because RegExp or programming.

You have a trouble extricly logic. The information you know is not enought to success with a priori rule/algorithm. You would need Artificial Intelligence here.

If the source string just have one '-', the operation is trivial.

If have more than one, and you dont know if are in the 1st substring or 2th; you lack of info, like some sort of dictionary that helps in knowing more data.

Edited by zalomalo

My english shucks, i know it.

Share this post


Link to post
Share on other sites

Can you post several lines of the data and what your expected results are? 


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

all that i know for sure about the string is that it contains at least one "-" and the string should be splitted in to two

 

To see several particular examples doesnt help isolating the trouble, but confusing. Analyzing and synthesizing the problem:

You must split a string in two; the separator is '-'. The separator is present allways once.

But, '-' can be present more times as not a separator. Hence, when you have just one '-', the operation is inmediate.

When you get '-' more times than one, you cant know witch one is the separator. You need deeper stated, with no other data '-' is not a valid separator in any case.

I insist, its a logic trouble.

Edited by zalomalo

My english shucks, i know it.

Share this post


Link to post
Share on other sites

zalomalo,

I insist, its a logic trouble.

 

Relax, just making sure all the bases are covered...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

And what about #8 , along with its extremely positive continuation #10  ?

Edit :  :D

Edited by mikell

Share this post


Link to post
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