Re: Detecting the presence of a pattern in an atom
Carlo Capelli <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CABty9wzxfnpssDuJbe4YHuhzWgMS4NQ9gYT+y=bjmfjNaOHeSQ@mail.gmail.com> |
2013/10/15 Steve Prior <[email protected]> > This is not a homework problem. > > I've been writing code which retrieves a list of titles from a web page > source and need to do a little pattern matching on each title. A title > might look like: > > Some name and some business name (ABC) > > I'm trying to get the "ABC". > > The titles don't have any formal grammar to them, but for starters I need > to see if there is a substring which starts with '(' contains all upper > case letters and ends with ')'. I suppose it's possible that the title > might contain multiple open/close parens, but I'd expect only one set to > fit the all upper case criterion. > > It seems a bit much to do a DCG grammar for this and I know that a regex > isn't the Prolog way of doing things, but don't remember what a better > option would be. I'm a bit rusty in Prolog, I picked it for this project > because of SWI's html parsing abilities which I've already put to good use. > > Michael regex pack, or XPCE regexes are available. ?- regex('\\(([A-Z]+)\\)', [], 'acme ltd (HELLO) 123', [P]), format('~s', [P]). HELLO P = [72, 69, 76, 76, 79] HTH Carlo > Any pointers? > > Steve > ______________________________**_________________ > SWI-Prolog mailing list > [email protected].**de <[email protected]> > https://lists.iai.uni-bonn.de/**mailman/listinfo.cgi/swi-**prolog<https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog> > -------------- next part -------------- HTML attachment scrubbed and removed