Question

Regex help, please

Asked by: EddieShipman

I need a regex to capture the text between 'asm' and 'end;' in this text:

asm
  MOV AX, 1234H
  MOV Number, AX
end;

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-07-09 at 13:46:25ID24558164
Topic

PHP Scripting Language

Participating Experts
3
Points
500
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Assembler > how to right use ASM and MOV in c++
    Forexample about joystick in my c++ program (Borland C++ Builder 3) I wrote long AAA,BBB; asm { mov ax,84h "or somethink like this" . . int 15h mov AAA,ax "and that is my problem" mov BBB,bx "and that is my problem"...
  2. __asm 'mov' illegal operand
    I have one more little question: I made code with this fragment in: //////// __asm { pushad mov edi,offset szWordtest /////// and now, after a lot of switching operations, It gives this error: ntpwc.cpp(111): error: __asm 'mov' i...
  3. Regex help
    Ok, new to regex and trying to figure this one out: sum(one+two+three+four) I want to get matches for one,two,three,four Thanks.
  4. Regex matching
    lets say I have an ip address "127.0.0.1" and i wanted to pull out all the numbers between the dots out Regex reg = new Regex("\.?(?<number>\d+)\.?"); Match mat = reg.Match("127.0.0.1"); I tried mat.results("$1-$4 but that was a no...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: cxrPosted on 2009-07-09 at 13:58:48ID: 24818275

Are you sure you need a regexp for that? Couldn't you just remove the three first and the four last characters?

Anyways, try this:

$string = "asm
  MOV AX, 1234H
  MOV Number, AX
end;";
preg_match('/asm(.+)end;/s',$string,$matches);
$asm = $matches[1];

                                              
1:
2:
3:
4:
5:
6:

Select allOpen in new window

 

by: EddieShipmanPosted on 2009-07-09 at 14:03:52ID: 24818322

This is to be used in the GeSHi highlighter written in PHP so I do need a regex. The above won't work for me.
I am testing in Expresso and the regex you posted returns nothing.

Thanks for trying, I guess I should have been a little more straightforward in my original post...

 

by: Ray_PaseurPosted on 2009-07-09 at 14:06:30ID: 24818346

Here is the non-REGEX solution.  I often find it is faster to just write a little bit of code for these simple extractions, versus taking the time to figure out a complicated (and possibly faluty) REGEX.

Best of luck with your project, ~Ray

<?php // RAY_temp_non_regex.php
error_reporting(E_ALL);
echo "<pre>\n";
 
// FROM THE OP
$txt = 'asm
  MOV AX, 1234H
  MOV Number, AX
end;';
 
// DELIMITERS
$a = 'asm';
$z = 'end;';
 
// GET AN ARRAY OF ELEMENTS BROKEN ON $a
$arr = explode($a, $txt);
// VISUALIZE THE RAW DATA
var_dump($arr);
echo "\n";
 
// ITERATE OVER THE ARRAY
foreach ($arr as $key => $val)
{
    if (empty($val)) continue;
    $val = ereg_replace("$z" . '$', '', trim($val));
    echo "\n$val";
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:

Select allOpen in new window

 

by: profyaPosted on 2009-07-09 at 14:12:16ID: 24818397

cxr solution missing an echo, it is working:

<?php
$string = "asm
  MOV AX, 1234H
  MOV Number, AX
end;";
preg_match('/asm(.+)end;/s',$string,$matches);
$asm = $matches[1];
echo $asm;
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: profyaPosted on 2009-07-09 at 14:14:00ID: 24818423

echo nl2br($asm);
to look like the input string.

 

by: EddieShipmanPosted on 2009-07-09 at 14:23:37ID: 24818511

Those options won't work for me as I stated earlier.

 

by: Ray_PaseurPosted on 2009-07-09 at 14:28:02ID: 24818542

@EddieShipman: We need you to explain a little more why these options will not work.  Is there more test data you can show us?  All of the examples here seem either 100% OK or 99% OK.

RSVP, ~Ray

 

by: profyaPosted on 2009-07-09 at 14:31:44ID: 24818568

Try this:

<?php
$string = "asm
  MOV AX, 1234H
  MOV Number, AX
end;";
if (ereg('asm(.+)end;',$string,$matches))
{
	$asm = $matches[1];
	echo nl2br($asm);
}
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: profyaPosted on 2009-07-09 at 14:34:12ID: 24818581

As Ray says, if this also not working, please let us know much more about the problem, since the solutions gays provided I test them all now, and they are all working fine. We are here for help.

 

by: EddieShipmanPosted on 2009-07-09 at 14:35:40ID: 24818589

They do not work in either Expresso nor the GeSHi highlighter for the text supplied.

As I stated, this is a regex for use inside the GeShi highlighter, it uses preg_replace to
highlight based on the regex passed.

The other options, as far as stripping out the asm and end; using explode, etc, aren't going to work
because this is for a language file for GeSHi.



 

by: profyaPosted on 2009-07-09 at 14:40:38ID: 24818620

Do you think that the line break affects the work of the above solutions?

 

by: EddieShipmanPosted on 2009-07-09 at 14:46:39ID: 24818659

Take, for instance, the CSS highlighter in GeSHi.

These regexes:

'REGEXPS' => array(
            0 => '\#[a-zA-Z0-9\-]+\s+\{',
            1 => '\.[a-zA-Z0-9\-]+\s',
            2 => ':[a-zA-Z0-9\-]+\s'
            ),


highlight this CSS:
#wrapheader {
      min-height: 120px;
      height: auto !important;
      height: 120px;
/*      background-image: url('./images/background.gif');
      background-repeat: repeat-x;*/
/*      padding: 0 25px 15px 25px;*/
      padding: 0;
}

#wrapcentre {
      margin: 15px 25px 0 25px;
}


like this:
<span style="color: #cc00cc;">#wrapheader <span style="color: #66cc66;">&#123;</span></span>
      min-<span style="color: #000000; font-weight: bold;">height</span>: 120px;
      <span style="color: #000000; font-weight: bold;">height</span>: <span style="color: #993333;">auto</span> !important;
      <span style="color: #000000; font-weight: bold;">height</span>: 120px;

<span style="color: #808080; font-style: italic;">/*      background-image: url('./images/background.gif');
      background-repeat: repeat-x;*/</span>
<span style="color: #808080; font-style: italic;">/*      padding: 0 25px 15px 25px;*/</span>
      <span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#wrapcentre <span style="color: #66cc66;">&#123;</span></span>
      <span style="color: #000000; font-weight: bold;">margin</span>: 15px 25px <span style="color: #cc66cc;">0</span> 25px;

<span style="color: #66cc66;">&#125;</span>

based on these values:
'REGEXPS' => array(
             0 => 'color: #cc00cc;',
            1 => 'color: #6666ff;',
            2 => 'color: #3333ff;',
            )

 

by: EddieShipmanPosted on 2009-07-09 at 14:47:34ID: 24818665

There are other styles for keywords such as background-color, font-weight, etc but they are not controlled
by the same parsing.

 

by: cxrPosted on 2009-07-09 at 18:21:57ID: 24819729

I have no experience with GeSHi, but based on the documentation:

http://qbnz.com/highlighter/geshi-doc.html#language-file-regexps

...I think you need something like this:

 array(
    GESHI_SEARCH => '(asm)(.*)(end;)',
    GESHI_REPLACE => '\\2',
    GESHI_MODIFIERS => 'si',
    GESHI_BEFORE => '\\1',
    GESHI_AFTER => '\\3'
    )

 

by: EddieShipmanPosted on 2009-07-10 at 15:06:44ID: 24827851

Well, that's very close. It makes the assembly code purple but the asm and end; lose their bold attributes.
What does the si modifier do?

 

by: cxrPosted on 2009-07-10 at 15:28:51ID: 24828019

The "s" is for matching linefeeds with the .* and the "i" means ignore case, ASM ... END; and Asm...End; would also be matched. Try adding bold like this:

 array(
    GESHI_SEARCH => '(asm)(.*)(end;)',
    GESHI_REPLACE => '<b>\\2</b>',
    GESHI_MODIFIERS => 'si',
    GESHI_BEFORE => '\\1',
    GESHI_AFTER => '<b>\\3</b>'
    )

 

by: EddieShipmanPosted on 2009-07-10 at 18:49:20ID: 24828713

Is there any way to ignore those matches?

 

by: cxrPosted on 2009-07-10 at 19:06:25ID: 24828760

"those"? Do you mean ASM ... END; and Asm...End; ? If so, just drop the "i" modifier.

 

by: EddieShipmanPosted on 2009-07-11 at 07:04:03ID: 24830478

Well, that one doesn't seem to help either. Here's the result:

<span style="color: #000000; font-weight: bold;">asm</span>
  MOV AX<span style="color: #000000;">,</span> 1234H
  MOV Number<span style="color: #000000;">,</span> AX
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000000;">;</span>

 

by: cxrPosted on 2009-07-11 at 07:36:12ID: 24830614

Where is the purple color you talked about earlier?

The <b> </b> tags are not there, did you use <span style="color: #000000; font-weight: bold;"> instead?

 

by: EddieShipmanPosted on 2009-07-11 at 12:13:07ID: 24831886

No, the color purple comes from the color values for the 2nd regex style:

'STYLES' => array(
   .
   .
   .
  'REGEXPS' => array(
    0 => 'color: #0000ff;',
    1 => 'color: #ff0000;',
    2 => 'color: #800080;'
    ),
   .
   .
   .
),

The 2nd style in the array goes with the 2nd regex in the REGEXPS array. See how CSS is done in post 24818659
above.

 

by: cxrPosted on 2009-07-15 at 13:46:35ID: 24863977

>> The 2nd style in the array goes with the 2nd regex in the REGEXPS array.

I don't know what is your second regexp. Which language are you creating/modifying a language file for? Could you post your complete language file and a sample source code that is supposed to work with that language file?

 

by: EddieShipmanPosted on 2009-07-15 at 13:59:56ID: 24864125

Below is entire language file and code snippet.
Needs to highlight like this:
http://www.delphicommunity.com/syntax.png

<?php
/*************************************************************************************
 * delphi.php
 * ----------
 * Author: Járja Norbert (jnorbi@vipmail.hu)
 * Copyright: (c) 2004 Járja Norbert, Nigel McNie (http://qbnz.com/highlighter)
 * Release Version: 1.0.7.1
 * CVS Revision Version: $Revision: 1.2 $
 * Date Started: 2004/07/26
 * Last Modified: $Date: 2005/07/26 05:23:30 $
 *
 * Delphi (Object Pascal) language file for GeSHi.
 *
 * CHANGES
 * -------
 * 2004/11/27 (1.0.1)
 *  -  Added support for multiple object splitters
 * 2004/10/27 (1.0.0)
 *   -  First Release
 *
 * TODO (updated 2004/11/27)
 * -------------------------
 *
 *************************************************************************************
 *
 *   This file is part of GeSHi.
 *
 *   GeSHi is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   GeSHi is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with GeSHi; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 ************************************************************************************/
// 2 => '/asm(.*?)end;/is'
 
$language_data = array (
  'LANG_NAME' => 'Delphi',
  'COMMENT_SINGLE' => array(1 => '//'),
  'COMMENT_MULTI' => array('(*' => '*)', '{' => '}'),
  'CASE_KEYWORDS' => 0,
  'QUOTEMARKS' => array("'", '"'),
  'ESCAPE_CHAR' => '',
  'KEYWORDS' => array(
    1 => array(
      'And', 'Array', 'As', 'Asm', 'Begin', 'Case', 'Class', 'Constructor', 'Destructor', 'Div', 'Do', 'DownTo', 'Else', 
      'End', 'Except', 'File', 'Finally', 'For', 'Function', 'Goto', 'If', 'Implementation', 'In', 'Inherited', 'Interface', 
      'Is', 'Mod', 'Not', 'Object', 'Of', 'On', 'Or', 'Packed', 'Private', 'Procedure', 'Program', 'Property', 'Protected',
                        'Published','Public', 'Raise', 'Record', 'Repeat', 'Set', 'Shl', 'Shr', 'Then', 'ThreadVar', 'To', 'Try', 'Unit', 
                        'Until', 'Uses', 'While', 'With', 'Xor','Strict'
      ),
    2 => array(
      'nil', 'false', 'true', 'var', 'type', 'const'
      ),
    3 => array(
      'Abs', 'Addr', 'AnsiCompareStr', 'AnsiCompareText', 'AnsiContainsStr', 'AnsiEndsStr', 'AnsiIndexStr', 'AnsiLeftStr',
      'AnsiLowerCase', 'AnsiMatchStr', 'AnsiMidStr', 'AnsiPos', 'AnsiReplaceStr', 'AnsiReverseString', 'AnsiRightStr',
      'AnsiStartsStr', 'AnsiUpperCase', 'ArcCos', 'ArcSin', 'ArcTan', 'Assigned', 'BeginThread', 'Bounds', 'CelsiusToFahrenheit',
      'ChangeFileExt', 'Chr', 'CompareStr', 'CompareText', 'Concat', 'Convert', 'Copy', 'Cos', 'CreateDir', 'CurrToStr',
      'CurrToStrF', 'Date', 'DateTimeToFileDate', 'DateTimeToStr', 'DateToStr', 'DayOfTheMonth', 'DayOfTheWeek', 'DayOfTheYear',
      'DayOfWeek', 'DaysBetween', 'DaysInAMonth', 'DaysInAYear', 'DaySpan', 'DegToRad', 'DeleteFile', 'DiskFree', 'DiskSize',
      'DupeString', 'EncodeDate', 'EncodeDateTime', 'EncodeTime', 'EndOfADay', 'EndOfAMonth', 'Eof', 'Eoln', 'Exp', 'ExtractFileDir',
      'ExtractFileDrive', 'ExtractFileExt', 'ExtractFileName', 'ExtractFilePath', 'FahrenheitToCelsius', 'FileAge',
      'FileDateToDateTime', 'FileExists', 'FilePos', 'FileSearch', 'FileSetDate', 'FileSize', 'FindClose', 'FindCmdLineSwitch',
      'FindFirst', 'FindNext', 'FloatToStr', 'FloatToStrF', 'Format', 'FormatCurr', 'FormatDateTime', 'FormatFloat', 'Frac',
      'GetCurrentDir', 'GetLastError', 'GetMem', 'High', 'IncDay', 'IncMinute', 'IncMonth', 'IncYear', 'InputBox',
      'InputQuery', 'Int', 'IntToHex', 'IntToStr', 'IOResult', 'IsInfinite', 'IsLeapYear', 'IsMultiThread', 'IsNaN',
      'LastDelimiter', 'Length', 'Ln', 'Lo', 'Log10', 'Low', 'LowerCase', 'Max', 'Mean', 'MessageDlg', 'MessageDlgPos',
      'MonthOfTheYear', 'Now', 'Odd', 'Ord', 'ParamCount', 'ParamStr', 'Pi', 'Point', 'PointsEqual', 'Pos', 'Pred',
      'Printer', 'PromptForFileName', 'PtInRect', 'RadToDeg', 'Random', 'RandomRange', 'RecodeDate', 'RecodeTime', 'Rect',
      'RemoveDir', 'RenameFile', 'Round', 'SeekEof', 'SeekEoln', 'SelectDirectory', 'SetCurrentDir', 'Sin', 'SizeOf',
      'Slice', 'Sqr', 'Sqrt', 'StringOfChar', 'StringReplace', 'StringToWideChar', 'StrToCurr', 'StrToDate', 'StrToDateTime',
      'StrToFloat', 'StrToInt', 'StrToInt64', 'StrToInt64Def', 'StrToIntDef', 'StrToTime', 'StuffString', 'Succ', 'Sum', 'Tan',
      'Time', 'TimeToStr', 'Tomorrow', 'Trunc', 'UpCase', 'UpperCase', 'VarType', 'WideCharToString', 'WrapText', 'Yesterday',
      'Append', 'AppendStr', 'Assign', 'AssignFile', 'AssignPrn', 'Beep', 'BlockRead', 'BlockWrite', 'Break',
      'ChDir', 'Close', 'CloseFile', 'Continue', 'DateTimeToString', 'Dec', 'DecodeDate', 'DecodeDateTime',
      'DecodeTime', 'Delete', 'Dispose', 'EndThread', 'Erase', 'Exclude', 'Exit', 'FillChar', 'Flush', 'FreeAndNil',
      'FreeMem', 'GetDir', 'GetLocaleFormatSettings', 'Halt', 'Inc', 'Include', 'Insert', 'MkDir', 'Move', 'New',
      'ProcessPath', 'Randomize', 'Read', 'ReadLn', 'ReallocMem', 'Rename', 'ReplaceDate', 'ReplaceTime',
      'Reset', 'ReWrite', 'RmDir', 'RunError', 'Seek', 'SetLength', 'SetString', 'ShowMessage', 'ShowMessageFmt',
      'ShowMessagePos', 'Str', 'Truncate', 'Val', 'Write', 'WriteLn'
      ),
    4 => array(
      'AnsiChar', 'AnsiString', 'Boolean', 'Byte', 'Cardinal', 'Char', 'Comp', 'Currency', 'Double', 'Extended',
      'Int64', 'Integer', 'LongInt', 'LongWord', 'PAnsiChar', 'PAnsiString', 'PChar', 'PCurrency', 'PDateTime',
      'PExtended', 'PInt64', 'Pointer', 'PShortString', 'PString', 'PVariant', 'PWideChar', 'PWideString',
      'Real', 'Real48', 'ShortInt', 'ShortString', 'Single', 'SmallInt', 'String', 'TBits', 'TConvType', 'TDateTime',
      'Text', 'TextFile', 'TFloatFormat', 'TFormatSettings', 'TList', 'TObject', 'TOpenDialog', 'TPoint',
      'TPrintDialog', 'TRect', 'TReplaceFlags', 'TSaveDialog', 'TSearchRec', 'TStringList', 'TSysCharSet',
      'TThreadFunc', 'Variant', 'WideChar', 'WideString', 'Word'
      ),
                
    ),
  'CASE_SENSITIVE' => array(
    GESHI_COMMENTS => true,
      1 => false,
      2 => false,
      3 => false,
      4 => false,
    ),
  'STYLES' => array(
    'KEYWORDS' => array(
      1 => 'color: #000000; font-weight: bold;',
      2 => 'color: #000000; font-weight: bold;',
      3 => 'color: #000000;',
      4 => 'color: #000000;',
      5 => 'color: #C0C0C0;'
      ),
    'COMMENTS' => array(
      1 => 'color: #808080; font-style: italic;',
      'MULTI' => 'color: #808080; font-style: italic;'
      ),
    'ESCAPE_CHAR' => array(
      ),
    'BRACKETS' => array(
      0 => 'color: #000000;'
      ),
    'STRINGS' => array(
      0 => 'color: #ff0000;'
      ),
    'NUMBERS' => array(
      0 => 'color: #0000ff;'
      ),
    'METHODS' => array(
      1 => 'color: #000000;'
      ),
    'REGEXPS' => array(
                0 => 'color: #0000ff;',
                1 => 'color: #ff0000;',
                2 => 'color: #800080; font-weight: bold;'
      ),
    'SYMBOLS' => array(
      0 => 'color: #000000;'
      ),
    'SCRIPT' => array(
      )
    ),
  'URLS' => array(
    1 => '',
    2 => '',
    3 => '',
    4 => ''
    ),
  'OOLANG' => true,
  'OBJECT_SPLITTERS' => array(
    1 => '.'
    ),
  'REGEXPS' => array(
          0 => '\$[0-9a-fA-F]+',
          1 => '\#\$?[0-9]{1,3}',
          2 => array(
                 GESHI_SEARCH => '(\asm)([a-z]+)(end;)', 
                 GESHI_REPLACE => '\\2',            
                 GESHI_MODIFIERS => '',             
                 GESHI_BEFORE => '\\1',             
                 GESHI_AFTER => '\\3'              
          )
    ),
  'STRICT_MODE_APPLIES' => GESHI_NEVER,
  'SCRIPT_DELIMITERS' => array(
    ),
  'HIGHLIGHT_STRICT_BLOCK' => array(
    )
);
 
?>
 
 
Delphi code snippet:
procedure TForm1.Button1Click(Sender:TObject);
var
  Number, I, X: Integer;
begin
  Number := 12356;
  Caption := 'The number is ' + IntToStr(Number);
  for I := 0 to Number do
  begin
    Inc(X);
    Dec(X);
    X := X + 1.0;
    ListBox1.Items.Add(IntToStr(X));
  end;
  asm
    MOX AX, 1234H
    MOV Number, AX
  end;
end;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:

Select allOpen in new window

 

by: cxrPosted on 2009-07-16 at 20:50:30ID: 24875773

I have tried to make this work without luck. The closest I get is with this rule:

array(
    GESHI_SEARCH => '(asm)(.*)(end)',
    GESHI_REPLACE => '\\2',
    GESHI_MODIFIERS => 'sU',
    GESHI_BEFORE => '\\1',
    GESHI_AFTER => '\\3'
    )

Note that I have removed the ; after end. This is because when this rule is applied, a previous rule have allready changed the ; into <span style="color: #000000;">;</span>, so there is no match for "end;".

I suspect that you can not do this with GeSHi, it seems it is not able to apply styles correctly to a section of code that allready has styles applied.

 

by: EddieShipmanPosted on 2009-07-17 at 05:25:18ID: 24877907

You know, now that you mention it, the asm and end are also being handled by another rule,
Is there a way to make it not "grab" the asm and end in the regex?

 

by: cxrPosted on 2009-07-17 at 05:31:03ID: 24877946

>> Is there a way to make it not "grab" the asm and end in the regex?

Not sure if I understand what you mean. You have to match them in the regexp to find them, but you are not grabbing them in the rule above, they are placed in GESHI_BEFORE and GESHI_AFTER, only the part in between (\\2) is placed in GESHI_REPLACE.

 

by: EddieShipmanPosted on 2009-07-17 at 07:08:13ID: 31601824

Well, it still isn't working so I'm going to post to the geshi-dev mailing list to see if I can get them to correct it.
It now comes out very weird. Thanks for the help. If I get a solution, I'll come back and post it here for you to see.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...