Jump to content

Stringregexp headach


 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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

Link to comment
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)
Link to comment
Share on other sites

/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.

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

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

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

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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...