Home page logo
/
Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News

Library re

Regular Expression functions

This is the re.lua module included in the LPeg distribution (http://www.inf.puc-rio.br/~roberto/lpeg/re.html)

Copyright© 2008-2010 Lua.org, PUC-Rio. (https://svn.nmap.org/nmap/docs/licenses/MIT)

Source: http://nmap.org/svn/nselib/re.lua

Functions

compile (string, defs)

Compiles the given string and returns an equivalent LPeg pattern.

find (subject, pattern, init)

Searches the given pattern in the given subject.

gsub (subject, pattern, replacement)

Global substitution.

match (subject, pattern, init)

Matches the given pattern against the given subject

updatelocale ()

Updates the pre-defined character classes to the current locale.



Functions

compile (string, defs)

Compiles the given string and returns an equivalent LPeg pattern.

The given string may define either an expression or a grammar. The optional defs table provides extra Lua values to be used by the pattern.

Parameters

  • string: a regular expression or an LPeg grammar
  • defs: Optional values to be used by the pattern

Return value:

an LPeg pattern
find (subject, pattern, init)

Searches the given pattern in the given subject.

If it finds a match, returns the index where this occurrence starts and the index where it ends. Otherwise, returns nil.

An optional numeric argument init makes the search starts at that position in the subject string. As usual in Lua libraries, a negative value counts from the end.

Parameters

  • subject: The string to search
  • pattern: A regular expression
  • init: Optional index into subject to start searching

Return values:

  1. index where the occurrence starts or nil
  2. index where the occurrence ends
gsub (subject, pattern, replacement)

Global substitution.

Does a global substitution, replacing all occurrences of pattern in the given subject by replacement.

Parameters

  • subject: The string to search
  • pattern: The pattern to match
  • replacement: The replacement for each pattern

Return value:

The string with all occurrences replaced
match (subject, pattern, init)

Matches the given pattern against the given subject

Matches the given pattern against the given subject, returning all captures.

Parameters

  • subject: The string to search
  • pattern: The pattern to match
  • init: Optional index into subject to start searching

Return value:

pattern captures
updatelocale ()

Updates the pre-defined character classes to the current locale.

Nmap Site Navigation

Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]