Jump to content

Parsing string


Recommended Posts

@Daydreamer067
Maybe something like this?

#include <Array.au3>
#include <StringConstants.au3>


Test()

Func Test()

    Local $arrResult

    $arrResult = StringRegExp("This is a test string with spaces." & @CRLF & _
                              "  Even with leading speaces,  double spaces, or trailing spaces    .",  _
                              '(\b\w+\b)', _
                              $STR_REGEXPARRAYGLOBALMATCH)

    _ArrayDisplay($arrResult)

EndFunc

^_^

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

The only information about the source we have is: "words separeted by space".
Nothing read about a point or anything else.
Especially if no point at all appears in the example of the questioner. The point was first introduced by Francesco.
So up to here, there is no reason to cover points extra.

Therefore, it does not make much sense to extend the task further than it was set.
Otherwise, one could also say that Francesco's code also extracts words that are not separated by spaces but only by semicolons.
For the task given so far, however, his code fulfills the task completely correctly and is sufficient until Daydreamer specifies the task further.

Edited by AspirinJunkie
Link to comment
Share on other sites

41 minutes ago, AspirinJunkie said:

... is sufficient until Daydreamer specifies the task further.

I would like to agree with @AspirinJunkie regarding this issue. The general conditions that the questioner has mentioned are insufficient for a more precise answer. Crystal balls are quite rare in our times :lol:.

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

1 hour ago, AspirinJunkie said:

The only information about the source we have is

In fact we have (spaces excepted) no information at all... 'parsing string' is very vague. Is this source string a text ? How should we parse "AutoIt v3 is a freeware BASIC-like scripting language." ?  :)
In such cases as usual we try to guess (maybe wrongly) what could be inside the subject 'string'

Link to comment
Share on other sites

 

52 minutes ago, mikell said:

In such cases as usual we try to guess (maybe wrongly) what could be inside the subject 'string'

fair enough, however what we use to try and guess is strongly influenced by what is presented, in this case:

11 hours ago, Daydreamer067 said:

"string exemple" would return string and exemple.

which, while admittedly offering little to go on, does not appear to be a sentence.
furthermore, at this point the OP doesn’t seem concerned with any subtle details:

11 hours ago, Daydreamer067 said:

I tried with StringRegExp but I don't know how to make it work.

and although he mentions specifically StringRegEx in his question,  the answer need not use such.

at this point though, I think the OP has been more than adequately served by all :)

Code hard, but don’t hard code...

Link to comment
Share on other sites

And this, ladies and gentlemen (I said gentlemen, so regex cats are not included), it's how a simple question become the official thread of "word or not word, this is the question" :D

Spoiler

For the regex cat @mikell, just kidding.

I love every regex pattern you post :cheer:

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

unless the OP returns, I’m thinking that we’ve been expertly trolled by someone who, (being aware of the community’s bitter divide  between those who RegEx and those who do not), has served up a perfectly ambiguous, right-down-the-middle-of-the-road question for us to squabble over, while he smugly sits back; chuckling as he mumbles “exemple”.

Code hard, but don’t hard code...

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