1

I have following format of transaction from core banking system

This is a <test>  and only <test> hope <u> understand

from where i want

<test><test><u> (along with <>)

with simple substring i can do that , but it will be too slow .. is there any way to capture a text between < and > using regex functions?

2
  • so you want the value in between the < and > in an array? Commented Nov 12, 2012 at 8:00
  • What is your expected output ? Commented Nov 12, 2012 at 8:23

2 Answers 2

1

The easiest I can think of is to use preg_match_all() and then join() the results together to form the final string:

function get_bracketed_words($str) 
{
    if (preg_match_all('/<[a-z]+>/', $str, $matches)) {
        return join('', $matches[0]);
    }
    return '';
}
Sign up to request clarification or add additional context in comments.

Comments

0

If you use this, it should not be too slow (Perl code as an example here):

while (my $line = <FILE>) {
    my ($request) = ($line =~ /RequestArray:(.*)/);
    next unless $request;
    # here, you can split $requests to sub-pieces using another regex
    # ...
}

1 Comment

Sorry I missed that you require PHP. But it should be easy rewrite in PHP

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.