collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: input message parser (regex)  (Read 5316 times)

0 Members and 2 Guests are viewing this topic.

Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
input message parser (regex)
« on: November 01, 2007, 10:01:43 pm »
Hey all,

Im trying to make a regular expressions that can handle all the bot commands.
well maybe this is not needed but, how do I do it otherwise?

I got it to grab multiply items from one command.

the code look like this:
Code: [Select]
<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2007
 */
$input 'loot add <a href="itemref://206204/206204/1">Twilight\'s Murder</a> <a href="itemref://223322/206204/1">I am gimp</a> test';
preg_match_all('/<a href="([^"]*)">([^<]*)<\/a>/im'$input$matchesPREG_SET_ORDER);
    
print_r($matches);
?>


and it result in this:
Code: [Select]
Array
(
    [0] => Array
        (
            [0] => <a href="itemref://206204/206204/1">Twilight's Murder</a>
            [1] => itemref://206204/206204/1
            [2] => Twilight's Murder
        )

    [1] => Array
        (
            [0] => <a href="itemref://223322/206204/1">I am gimp</a>
            [1] => itemref://223322/206204/1
            [2] => I am gimp
        )

)

but I still lack to be able to grab loot add and test

I tryed to put in (\w*) thro it give all kind of diffrent output.

The output im looking for is this:
Code: [Select]
Array
(
    [0] => Array
       (
            [0] => loot
       )
    [1] => Array
       (
            [0] => add
       )
    [2] => Array
       (
            [0] => <a href="itemref://206204/206204/1">Twilight's Murder</a>
            [1] => itemref://206204/206204/1
            [2] => Twilight's Murder
        )

    [3] => Array
        (
            [0] => <a href="itemref://223322/206204/1">I am gimp</a>
            [1] => itemref://223322/206204/1
            [2] => I am gimp
        )
    [4] => Array
       (
            [0] => test
       )
)

this parser should be working with all count of pre word/numbers and after word/numbers :)
« Last Edit: November 01, 2007, 10:04:09 pm by lazarus »

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: input message parser (regex)
« Reply #1 on: November 01, 2007, 10:12:38 pm »
I do not understand the question.
The only problem that can't be solved by adding another wrapper is having too many wrappers.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: input message parser (regex)
« Reply #2 on: November 01, 2007, 11:16:02 pm »
The regular expression returns exactly what it's supposed to. Maybe you'll have to use more then one regular expression, or a more general one, or split up the input before preg_match(). I doubt that it's possible to match your wished output format exactly though.

Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
Re: input message parser (regex)
« Reply #3 on: November 02, 2007, 10:15:18 am »
The regular expression returns exactly what it's supposed to. Maybe you'll have to use more then one regular expression, or a more general one, or split up the input before preg_match(). I doubt that it's possible to match your wished output format exactly though.

ok how do I split it up?

I just want to be able to check against the words and items.


Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
Re: input message parser (regex)
« Reply #4 on: November 02, 2007, 10:20:11 am »
I do not understand the question.

I want to put the input string
Code: [Select]
"loot add <a href="itemref://206204/206204/1">Twilight\'s Murder</a> <a href="itemref://223322/206204/1">I am gimp</a> test"
into a array with each section in it.
as in

loot, add, first item, 2nd item, test.

So I can if ($output[4] == "test") echo "this is what I want";
and so on :)

Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
Re: input message parser (regex)
« Reply #5 on: November 02, 2007, 05:01:29 pm »
I found the solution that I can use.

Code: [Select]
<pre>
<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2007
 */

$str 'Søg på <a href="http://www.google.com/">google</a> <a href="http://www.google.com/">google</a> for at finde det du mangler';
$chars preg_split('/(<a.*<\/a>)/im'$str, -1PREG_SPLIT_DELIM_CAPTURE);
print_r($chars);
?>

</pre>

that give this result :) :
Code: [Select]
<pre>
Array
(
    [0] => Søg på
    [1] => <a href="http://www.google.com/">google</a> <a href="http://www.google.com/">google</a>
    [2] =>  for at finde det du mangler
)
</pre>

from this I know that chars[0] is all before the items, chars[1] is all items posted and chars[2] is everything after items

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 187
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal