How to use the regex.set_syntax function in regex

To help you get started, we’ve selected a few regex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github larryhastings / gilectomy / Lib / dos-8x3 / test_reg.py View on Github external
from test_support import verbose
import regex
from regex_syntax import *

re = 'a+b+c+'
print 'no match:', regex.match(re, 'hello aaaabcccc world')
print 'successful search:', regex.search(re, 'hello aaaabcccc world')
try:
    cre = regex.compile('\(' + re)
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'

print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
prev = regex.set_syntax(RE_SYNTAX_AWK)
print 'successful awk syntax:', regex.search('(a+)|(b+)', 'cdb')
regex.set_syntax(prev)
print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')

re = '\([0-9]+\) *\([0-9]+\)'
print 'matching with group names and compile()'
cre = regex.compile(re)
print cre.match('801 999')
try:
    print cre.group('one')
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'

print 'matching with group names and symcomp()'
github larryhastings / gilectomy / Lib / lib-old / grep.py View on Github external
def ggrep(syntax, pat, files):
    if len(files) == 1 and type(files[0]) == type([]):
        files = files[0]
    global opt_show_filename
    opt_show_filename = (len(files) != 1)
    syntax = regex.set_syntax(syntax)
    try:
        prog = regex.compile(pat)
    finally:
        syntax = regex.set_syntax(syntax)
    for filename in files:
        fp = open(filename, 'r')
        lineno = 0
        while 1:
            line = fp.readline()
            if not line: break
            lineno = lineno + 1
            if prog.search(line) >= 0:
                showline(filename, lineno, line, prog)
        fp.close()
github scs / uclinux / user / python / Lib / lib-old / grep.py View on Github external
def ggrep(syntax, pat, files):
    if len(files) == 1 and type(files[0]) == type([]):
        files = files[0]
    global opt_show_filename
    opt_show_filename = (len(files) != 1)
    syntax = regex.set_syntax(syntax)
    try:
        prog = regex.compile(pat)
    finally:
        syntax = regex.set_syntax(syntax)
    for filename in files:
        fp = open(filename, 'r')
        lineno = 0
        while 1:
            line = fp.readline()
            if not line: break
            lineno = lineno + 1
            if prog.search(line) >= 0:
                showline(filename, lineno, line, prog)
        fp.close()
github larryhastings / gilectomy / Demo / tkinter / guido / regexdemo.py View on Github external
def newsyntax(self):
		syntax = 0
		for var in self.vars:
			syntax = syntax | var.get()
		regex.set_syntax(syntax)
		self.recompile()
github scs / uclinux / user / python / Lib / lib-old / grep.py View on Github external
def ggrep(syntax, pat, files):
    if len(files) == 1 and type(files[0]) == type([]):
        files = files[0]
    global opt_show_filename
    opt_show_filename = (len(files) != 1)
    syntax = regex.set_syntax(syntax)
    try:
        prog = regex.compile(pat)
    finally:
        syntax = regex.set_syntax(syntax)
    for filename in files:
        fp = open(filename, 'r')
        lineno = 0
        while 1:
            line = fp.readline()
            if not line: break
            lineno = lineno + 1
            if prog.search(line) >= 0:
                showline(filename, lineno, line, prog)
        fp.close()
github larryhastings / gilectomy / Misc / faq2html.py View on Github external
#     preformatted section       
#
# Heading level is determined by the number of () segments.
# Blank lines force a separation of elements; if none of the above four
# types is indicated, a new paragraph begins.  A line beginning with many
# spaces is interpreted as a continuation (instead of preformatted) after
# a list element.  Headings are anchored; paragraphs starting with "Q." are
# emphasized, and those marked with "A." get their first sentence emphasized.
#
# Hyperlinks are created from references to:
#     URLs, explicitly marked using  
#     other questions, of the form "question ()*"
#     sections, of the form "section ".

import sys, string, regex, regsub, regex_syntax
regex.set_syntax(regex_syntax.RE_SYNTAX_AWK)

# --------------------------------------------------------- regular expressions
orditemprog = regex.compile('  ?([1-9][0-9]*\.)+ +')
itemprog = regex.compile(' ? ?[-*] +')
headingprog = regex.compile('([1-9][0-9]*\.)+ +')
prefmtprog = regex.compile('   ')
blankprog = regex.compile('^[ \t\r\n]$')
questionprog = regex.compile(' *Q\. +')
answerprog = regex.compile(' *A\. +')
sentprog = regex.compile('(([^.:;?!(]|[.:;?!][^ \t\r\n])+[.:;?!]?)')

mailhdrprog = regex.compile('^(Subject|Newsgroups|Followup-To|From|Reply-To'
    '|Approved|Archive-Name|Version|Last-Modified): +', regex.casefold)
urlprog = regex.compile('<URL:([^&]+)>')
addrprog = regex.compile('<([^>@:]+@[^&@:]+)>')
qrefprog = regex.compile('question +([1-9](\.[0-9]+)*)')
github larryhastings / gilectomy / Lib / lib-old / grep.py View on Github external
def ggrep(syntax, pat, files):
    if len(files) == 1 and type(files[0]) == type([]):
        files = files[0]
    global opt_show_filename
    opt_show_filename = (len(files) != 1)
    syntax = regex.set_syntax(syntax)
    try:
        prog = regex.compile(pat)
    finally:
        syntax = regex.set_syntax(syntax)
    for filename in files:
        fp = open(filename, 'r')
        lineno = 0
        while 1:
            line = fp.readline()
            if not line: break
            lineno = lineno + 1
            if prog.search(line) >= 0:
                showline(filename, lineno, line, prog)
        fp.close()