[Gambas-user] Re gular Expression Help
hinchy
eoinhinchy at ...626...
Tue May 27 19:37:51 CEST 2008
Thanks lads, that's really nice code, a big help. If you get a chance maybe
you could explain how regular expressions are used in gambas.
I know the documentation says:
DIM hRegexp AS Regexp
hRegexp = NEW Regexp ( [ Subject AS String, Pattern AS String,
CompileOptions AS Integer, ExecOptions AS Integer ] )
I can't really figure out how to apply this though.
Thanks again.
M0E Lnx wrote:
>
> Throw it into an array..
>
> DIM sList as string[]
> dim sStr as string
> DIM i as integer
> dim sOneDev as string
>
> SHELL "ls -m /dev | grep [sh]d[a-z]" to sStr
> sList = Split(sStr, ",")
>
> FOR i = 0 to sList.Count - 1
> sOneDev = left(trim(sList[i]), 3)
> Print sOneDev
> Next
>
> This first, produce a list separated by commas, then use a gambas
> array to separate the array into separate strings. After that, you run
> the FOR Loop to trim out the text you need
>
> Unless I'm not understanding this right.
>
>
> On 5/27/08, Stefano Palmeri <rospolosco at ...152...> wrote:
>> Il Tuesday 27 May 2008 18:17:23 Stefano Palmeri ha scritto:
>>
>> > Il Tuesday 27 May 2008 17:22:35 hinchy ha scritto:
>> > > Yeah I thought about doing something like that, the thing is though,
>> I
>> > > won't always know how long the first word is. With the regex I can
>> match
>> > > until the first white space. Is there a way of doing that with text
>> > > splitting? If so great. If not is there anywhere you could suggest I
>> look
>> > > for example regex implementation in gambas?
>> > >
>> > > Thanks again.
>> >
>> > I don't understand your problem (my fault). Here's a way to
>> > extracy only "sda".
>> >
>> > DIM sStr, sOneDev AS String
>> >
>> > SHELL "ls /dev | grep [sh]d[a-z]" TO sStr
>> >
>> > FOR EACH sOneDev IN Split(sStr, "\n")
>> >
>> > IF sOneDev = "sda" THEN BREAK
>> >
>> > NEXT
>> >
>> > PRINT sOneDev
>> >
>> > Bye
>> >
>>
>>
>> or:
>>
>> IF sOneDev LIKE "sd[a-z]" THEN BREAK
>>
>>
>>
>>
>>
>>
>>
>>
>> > > M0E Lnx wrote:
>> > > > why not just do some text splitting to get what you need?
>> > > >
>> > > > If you have "sda1" and you only want "sda" out of that... you
>> should
>> > > > be able to go with Newstring=left(sStr, 3)
>> > > >
>> > > > On 5/27/08, hinchy <eoinhinchy at ...626...> wrote:
>> > > >> keywords: regex, Regular Expression, regexp, pcre
>> > > >>
>> > > >> Hi guys,
>> > > >>
>> > > >> I've been struggling with the pcre component for a couple of
>> days
>> > > >> now. I'm
>> > > >> running the command:
>> > > >> SHELL "ls /dev | grep [sh]d[a-z]" TO sStr
>> > > >>
>> > > >> This will return something along the lines of:
>> > > >> sda
>> > > >> sda1
>> > > >> sda2
>> > > >>
>> > > >> I then want to run the regular expression ^[^\s]*+ against sStr
>> to
>> > > >> return
>> > > >> sda for saving in a different string but I can't for the life of
>> my
>> > > >> figure
>> > > >> it out.
>> > > >> Any ideas? I'm sure it's quite simple I just can't get it
>> together.
>> > > >> Thanks,
>> > > >> Eoin
>> > > >> --
>> > > >> View this message in context:
>> > > >>
>> http://www.nabble.com/Regular-Expression-Help-tp17488070p17488070.html
>> > > >> Sent from the gambas-user mailing list archive at Nabble.com.
>> > > >>
>> > > >>
>> > > >>
>> > > >>
>> ----------------------------------------------------------------------
>> > > >>-- - This SF.net email is sponsored by: Microsoft
>> > > >> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> > > >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> > > >> _______________________________________________
>> > > >> Gambas-user mailing list
>> > > >> Gambas-user at lists.sourceforge.net
>> > > >> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> > > >
>> > > >
>> -----------------------------------------------------------------------
>> > > >-- This SF.net email is sponsored by: Microsoft
>> > > > Defy all challenges. Microsoft(R) Visual Studio 2008.
>> > > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> > > > _______________________________________________
>> > > > Gambas-user mailing list
>> > > > Gambas-user at lists.sourceforge.net
>> > > > https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >
>> >
>> -------------------------------------------------------------------------
>> > This SF.net email is sponsored by: Microsoft
>> > Defy all challenges. Microsoft(R) Visual Studio 2008.
>> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> > _______________________________________________
>> > Gambas-user mailing list
>> > Gambas-user at lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>>
>> -------------------------------------------------------------------------
>>
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
--
View this message in context: http://www.nabble.com/Regular-Expression-Help-tp17488070p17495939.html
Sent from the gambas-user mailing list archive at Nabble.com.
More information about the User
mailing list