Create regex pattern for fluentd - ruby

I'm using Fluentd configuration and regexp parser to parse the logs.
This are my original logs in fluentd:
2022-09-22 18:15:09,633 [springHikariCP housekeeper ] DEBUG HikariPool - springHikariCP - Fill pool skipped, pool is at sufficient level.
2022-09-22 18:15:14,968 [ringHikariCP connection closer] DEBUG PoolBase - springHikariCP - Closing connection com.mysql.cj.jdbc.ConnectionImpl#7f535ea4: (connection has passed maxLifetime)
I want to create json format for the above logs with regexp like this:
{
"logtime": "2022-09-22 18:15:09,633",
"Logger Name": "[springHikariCP housekeeper ]",
"Log level": "DEBUG",
"message": "HikariPool - springHikariCP - Fill pool skipped, pool is at sufficient level"
}
{
"logtime": "2022-09-22 18:15:09,633",
"Logger Name": "[ringHikariCP connection closer]",
"Log level": "DEBUG",
"message": "PoolBase - springHikariCP - Closing connectioncom.mysql.cj.jdbc.ConnectionImpl#7f535ea4: (connection has passed maxLifetime)"
}
Can someone with Ruby expirience help me to create Ruby regex for this logs above

The regex should be straightforward, e.g.
(?'logtime'\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s(?'logname'\[[^\]]*\])\s(?'loglevel'\w+)\s(?'message'.*)
Online Test
And then, reassemble the parts using a substitution (gsub, see example below) or putting a new string together from the parts (match) :
re = /(?'logtime'\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s(?'logname'\[[^\]]*\])\s(?'loglevel'\w+)\s(?'message'.*?$)/m
str = '2022-09-22 18:15:09,633 [springHikariCP housekeeper ] DEBUG HikariPool - springHikariCP - Fill pool skipped, pool is at sufficient level.
2022-09-22 18:15:14,968 [ringHikariCP connection closer] DEBUG PoolBase - springHikariCP - Closing connection com.mysql.cj.jdbc.ConnectionImpl#7f535ea4: (connection has passed maxLifetime)'
str.gsub(re) do |match|
puts "{
\"logtime\": \"#{$~[:logtime]}\",
\"Logger Name\": \"#{$~[:logname]}\",
\"Log level\": \"#{$~[:loglevel]}\",
\"message\": \"#{$~[:message]}\"
}"
end

Related

How can I turn off netty client DNS connect retry?

I'm using Netty-httpClient for Spring webClient.
When I connect www.naver.com and set the host like this.
127.0.0.1 www.naver.com
125.209.222.142 www.naver.com
And run httpClient.get() result like this.
DEBUG r.n.r.PooledConnectionProvider - [id:83c8069f] Created a new pooled channel, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.
DEBUG r.n.t.SslProvider - [id:83c8069f] SSL enabled using engine sun.security.ssl.SSLEngineImpl#5412b204 and SNI www.naver.com:443
DEBUG i.n.b.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
DEBUG i.n.b.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true
DEBUG i.n.u.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector#7ec1e7a5
DEBUG r.n.t.TransportConfig - [id:83c8069f] Initialized pipeline DefaultChannelPipeline{(reactor.left.sslHandler = io.netty.handler.ssl.SslHandler), (reactor.left.loggingHandler = reactor.netty.transport.logging.ReactorNettyLoggingHandler), (reactor.left.sslReader = reactor.netty.tcp.SslProvider$SslReadHandler), (reactor.left.httpCodec = io.netty.handler.codec.http.HttpClientCodec), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}
INFO reactor - [id:83c8069f] REGISTERED
DEBUG r.n.t.TransportConnector - [id:83c8069f] Connecting to [www.naver.com/127.0.0.1:443].
INFO reactor - [id:83c8069f] CONNECT: www.naver.com/127.0.0.1:443
INFO reactor - [id:83c8069f] CLOSE
DEBUG r.n.t.TransportConnector - [id:83c8069f] Connect attempt to [www.naver.com/127.0.0.1:443] failed.
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: www.naver.com/127.0.0.1:443
Caused by: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
DEBUG r.n.r.PooledConnectionProvider - [id:0e3c272c] Created a new pooled channel, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.
DEBUG r.n.t.SslProvider - [id:0e3c272c] SSL enabled using engine sun.security.ssl.SSLEngineImpl#47b241b and SNI www.naver.com:443
DEBUG r.n.t.TransportConfig - [id:0e3c272c] Initialized pipeline DefaultChannelPipeline{(reactor.left.sslHandler = io.netty.handler.ssl.SslHandler), (reactor.left.loggingHandler = reactor.netty.transport.logging.ReactorNettyLoggingHandler), (reactor.left.sslReader = reactor.netty.tcp.SslProvider$SslReadHandler), (reactor.left.httpCodec = io.netty.handler.codec.http.HttpClientCodec), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}
INFO reactor - [id:0e3c272c] REGISTERED
INFO reactor - [id:83c8069f] UNREGISTERED
DEBUG r.n.t.TransportConnector - [id:0e3c272c] Connecting to [www.naver.com/125.209.222.142:443].
INFO reactor - [id:0e3c272c] CONNECT: www.naver.com/125.209.222.142:443
DEBUG r.n.r.DefaultPooledConnectionProvider - [id:0e3c272c, L:/192.168.55.77:52910 - R:www.naver.com/125.209.222.142:443] Registering pool release on close event for channel
DEBUG r.n.r.PooledConnectionProvider - [id:0e3c272c, L:/192.168.55.77:52910 - R:www.naver.com/125.209.222.142:443] Channel connected, now: 1 active connections, 0 inactive connections and 0 pending acquire requests.
DEBUG i.n.u.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
DEBUG i.n.u.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
DEBUG i.n.u.Recycler - -Dio.netty.recycler.linkCapacity: 16
DEBUG i.n.u.Recycler - -Dio.netty.recycler.ratio: 8
DEBUG i.n.u.Recycler - -Dio.netty.recycler.delayedQueue.ratio: 8
INFO reactor - [id:0e3c272c, L:/192.168.55.77:52910 - R:www.naver.com/125.209.222.142:443] ACTIVE
see that. I don't want connect twice and don't spend more time to connect.
just fail if can not make connect.
Can I avoid this situation?
This is managing under the issue.
https://github.com/reactor/reactor-netty/issues/1822

apache nifi Stateless - not able to set parm of controller service (DBCPConnectionPool 1.10.0)

I am following the NiFi 1.10 stateless guildeline to create a simple process group of executing a sql in mysql db. I have put necessary parm of db controller service to parameter context.
it works well in nifi canvas. Then i add it to registry and prepare a json parm file: stateless-simpledb.json
{
"registryUrl": "http://localhost:18080",
"bucketId": "cac8f127-e328-45c1-a4cb-0e03dc837ceb",
"flowId": "cc2753f2-78f3-4449-a2fd-343dfeaafe15",
"flowVersion": "3",
"parameters": {
"lastIngestId" : "20000",
"mysql-jdbc-driver-name" : "com.mysql.jdbc.Driver",
"db-user" : "root",
"db-password" : "password",
"db-con-url" : "jdbc:mysql://localhost:3306/mms",
"jdbc-jar-path" : "/program/jdbc/mysql-connector-java.jar"
}
}
and run the one-off command:
/program/nifi/bin/nifi.sh stateless RunFromRegistry Once --file /app/poc/nifi-stateless/conf/stateless-simpledb.json
It raise error:
=== FlowFileRepository Type ===
org.apache.nifi.controller.repository.RocksDBFlowFileRepository
org.apache.nifi:nifi-framework-nar:1.10.0 || /program/nifi-1.10.0/work/stateless-nars/nifi-framework-nar-1.10.0.nar-unpacked
org.apache.nifi.controller.repository.WriteAheadFlowFileRepository
org.apache.nifi:nifi-framework-nar:1.10.0 || /program/nifi-1.10.0/work/stateless-nars/nifi-framework-nar-1.10.0.nar-unpacked
org.apache.nifi.controller.repository.VolatileFlowFileRepository
org.apache.nifi:nifi-framework-nar:1.10.0 || /program/nifi-1.10.0/work/stateless-nars/nifi-framework-nar-1.10.0.nar-unpacked
=== End FlowFileRepository types ===
23:32:32.626 [main] INFO org.apache.nifi.stateless.bootstrap.ExtensionDiscovery - Successfully discovered extensions in 4411 milliseconds
23:32:32.633 [main] DEBUG org.apache.nifi.stateless.core.ComponentFactory - Setting context class loader to org.apache.nifi.nar.InstanceClassLoader#50fa5938 (parent = org.apache.nifi.nar.NarClassLoader[/program/nifi-1.10.0/work/stateless-nars/nifi-dbcp-service-nar-1.10.0.nar-unpacked]) to create org.apache.nifi.dbcp.DBCPConnectionPool
23:32:32.647 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input #{jdbc-jar-path} found 1 Parameter references: [org.apache.nifi.parameter.StandardParameterReference#2d3eecda]
23:32:32.650 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input /program/jdbc/mysql-connector-java.jar found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input 500 millis found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input 8 found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input 0 found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input 8 found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input -1 found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input -1 found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input 30 mins found 0 Parameter references: []
23:32:32.651 [main] DEBUG org.apache.nifi.parameter.ExpressionLanguageAwareParameterParser - For input -1 found 0 Parameter references: []
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.nifi.bootstrap.RunStatelessNiFi.main(RunStatelessNiFi.java:69)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.nifi.StatelessNiFi.main(StatelessNiFi.java:103)
... 5 more
Caused by: java.lang.RuntimeException: Failed to enable Controller Service {id=691ecc97-ff46-3a5e-8aad-37dc568bc247, name=MYSQL-MMS-stateless-test, type=class org.apache.nifi.dbcp.DBCPConnectionPool} because validation failed: ['Database Connection URL' is invalid because Database Connection URL is required, 'Database Driver Class Name' is invalid because Database Driver Class Name is required]
at org.apache.nifi.stateless.core.StatelessControllerServiceLookup.enableControllerServices(StatelessControllerServiceLookup.java:133)
at org.apache.nifi.stateless.core.StatelessFlow.<init>(StatelessFlow.java:153)
at org.apache.nifi.stateless.core.StatelessFlow.createAndEnqueueFromJSON(StatelessFlow.java:469)
at org.apache.nifi.stateless.runtimes.Program.runLocal(Program.java:133)
at org.apache.nifi.stateless.runtimes.Program.launch(Program.java:67)
... 10 more
Seems the apache nifi stateless function failed to set controller service even it's in "process group" scope.
Would anyone has any advice?
As mentioned in the comments, this appears to be a known problem with the validation of controller services.
This can be avoided by using Nifi 1.12 and above as it got fixed in the following jira: https://issues.apache.org/jira/plugins/servlet/mobile#issue/NIFI-7380
Though I am not entirely sure of this, it may also be possible that this simply indicates that your controller service is not configured correctly. This would be worth double checking.

Too many connections are getting created

I have gone through the HikariCP connection pool, I could say this is awesome as I have seen good performance. But here my concern is I think it is taking too many connections.
Scenario:
I have list object which contains 10004 records and when I ran insert query it is taking 13 seconds to complete the operation.
DB Properties:
final HikariDataSource dataSource = new HikariDataSource();
dataSource.setMaximumPoolSize(100);
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
dataSource.setJdbcUrl("jdbc:oracle:thin:#g9u1769.houston.hpecorp.net:1525:ODSDBD");
dataSource.setUsername("Solid_batch1");
dataSource.setPassword("solid_batch123");
dataSource.setMaxLifetime(30000);
log:
2016-08-27 11:26:01.779 [] [] [] [Hikari connection adder (pool HikariPool-0)] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-0 - Added connection oracle.jdbc.driver.T4CConnection#221e8d6a
2016-08-27 11:26:04.204 [] [] [] [Hikari connection adder (pool HikariPool-0)] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-0 - Added connection oracle.jdbc.driver.T4CConnection#3c4ecbf
2016-08-27 11:26:06.620 [] [] [] [Hikari connection adder (pool HikariPool-0)] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-0 - Added connection oracle.jdbc.driver.T4CConnection#7592f187
2016-08-27 11:26:09.038 [] [] [] [Hikari connection adder (pool HikariPool-0)] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-0 - Added connection oracle.jdbc.driver.T4CConnection#22f125f
2016-08-27 11:26:11.455 [] [] [] [Hikari connection adder (pool HikariPool-0)] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-0 - Added connection oracle.jdbc.driver.T4CConnection#605f1c17
2016-08-27 11:26:13.869 [] [] [] [Hikari connection adder (pool HikariPool-0)] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-0 - Added connection oracle.jdbc.driver.T4CConnection#42d5b6f
2016-08-27 11:26:13.975 [] [] [] [main] WARN c.h.i.i.d.manager.dao.DaoService - detail query : 13
Can anyone help me in reducing the connection creation.
you can reduce maximum pool size so connection will be restrict to that and then it not make more connection instead it will use once defined connection is free to use by setting :
dataSource.setMaximumPoolSize(20);

JSMPP - MO Received but Short Message Byte Array Empty

I'm having a problem processing MO requests from a specific SMSC connection using jsmpp.
The connection in question is properly bound and works perfectly for MT requests; however, when we get the callback that an MO is received, the short_message property of the PDU reads as blank. Here is a print out of what I see in the logs:
02:05:47,255 DEBUG [SmppConnectionManagerImpl] onAcceptDeliverSm: From: 9178386944 To: 2184 ESM: 0 Msg:
02:05:47,255 DEBUG [SmppConnectionManagerImpl] BYTE ARRAY LENGTH
02:05:47,256 DEBUG [SmppConnectionManagerImpl] 0
02:05:47,256 DEBUG [SmppConnectionManagerImpl] COMMAND STATUS
02:05:47,256 DEBUG [SmppConnectionManagerImpl] 0
02:05:47,256 DEBUG [SmppConnectionManagerImpl] DATA CODING
02:05:47,256 DEBUG [SmppConnectionManagerImpl] 0
02:05:47,256 DEBUG [SmppConnectionManagerImpl] COMMAND LENGTH
02:05:47,256 DEBUG [SmppConnectionManagerImpl] 114
02:05:47,256 DEBUG [SmppConnectionManagerImpl] -
02:05:47,256 DEBUG [SmppConnectionManagerImpl]
02:05:47,256 DEBUG [SmppConnectionManagerImpl] -
02:05:47,256 DEBUG [SmppConnectionManagerImpl]
02:05:47,256 DEBUG [SmppConnectionManagerImpl] -
02:05:47,256 DEBUG [SmppConnectionManagerImpl]
02:05:47,256 DEBUG [SmppConnectionManagerImpl] -
02:05:47,256 DEBUG [SmppConnectionManagerImpl]
02:05:47,256 DEBUG [SmppConnectionManagerImpl] -
02:05:47,256 DEBUG [SmppConnectionManagerImpl]
02:05:47,256 DEBUG [SmppConnectionManagerImpl] ========
And the code that produced it:
LOG.debug("onAcceptDeliverSm: From: {} To: {} ESM: {} Msg: {}", deliverSm.getSourceAddr(),
deliverSm.getDestAddress(), deliverSm.getEsmClass(), new String(deliverSm.getShortMessage()));
LOG.debug("BYTE ARRAY LENGTH");
LOG.debug(Integer.toString(deliverSm.getShortMessage().length));
LOG.debug("COMMAND STATUS");
LOG.debug(Integer.toString(deliverSm.getCommandStatus()));
LOG.debug("DATA CODING");
LOG.debug(Integer.toString(new Byte(deliverSm.getDataCoding()).intValue()));
LOG.debug("COMMAND LENGTH");
LOG.debug(Integer.toString(deliverSm.getCommandLength()));
LOG.debug("-");
LOG.debug(new String(deliverSm.getShortMessage(), Charset.forName("US-ASCII")));
LOG.debug("-");
LOG.debug(new String(deliverSm.getShortMessage(), Charset.forName("ISO-8859-1")));
LOG.debug("-");
LOG.debug(new String(deliverSm.getShortMessage(), Charset.forName("UTF-16BE")));
LOG.debug("-");
LOG.debug(new String(deliverSm.getShortMessage(), Charset.forName("UTF-16LE")));
LOG.debug("-");
LOG.debug(new String(deliverSm.getShortMessage(), Charset.forName("UTF-16")));
As you can see, we are getting data from the SMSC; however, when we try to read out the short message, it returns an empty byte array. Other fields (like the source and dest address) are returning okay.
Additionally, when we have people send variable length MOs, the command length is variable - indicating that the data is there somehow, it's just not able to be read for some reason.
Would appreciate any leads on things that could cause the short message byte array to come back as blank and configuration settings to try to fix the problem.
This ended up being an issue with the way the SMSC in question packaged it's responses. In their case, rather than sending the message data in short_message part of the PDU, the message data was being sent in the optional message_payload part of the PDU.
Here is the code we ended up with to parse out the message
private String getMessageBody(DeliverSm deliverSm) {
byte[] bytes = Optional.ofNullable(deliverSm.getOptionalParameter(OptionalParameter.Message_payload.class))
.map(x -> x.getValue())
.filter(x -> x != null && x.length > 0)
.orElse(deliverSm.getShortMessage());
return Optional.ofNullable(bytes)
.filter(x -> x != null && x.length > 0)
.map(x -> new String(x, UTF8))
.orElse("");
}
Had same problem. All I needed to resolve it was to upgrade to jsmpp 2.2.jar.
In addition, the code could not distinguish between SMSC_DELIVERY_RECEIPT type messages and MO type messages.
All this "bugs?" were fixed when I upgraded to the newer library.
Thanks.

regex match one instance of a pattern that repeats

Given the following regex
/(500 Internal Server Error)/
How do we match only the 1st occurrence of this pattern in a single string that has many repeats of the same match?
For example:
Match 1
1. 500 Internal Server Error
Match 2
1. 500 Internal Server Error
Match 3
1. 500 Internal Server Error
How do we get 1. as our only answer?
Sample text for the match as follows (one big string on purpose)
[SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 500 Internal Server Error12:09:26,638 INFO [SoapUIProTestCaseRunner] Assertion [Match content of [question]] has status VALID12:09:26,638 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection 0.0.0.0:41494<->23.6.55.1:80 shut down12:09:26,638 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection 0.0.0.0:41494<->23.6.55.1:80 closed12:09:26,638 INFO [SoapUIProTestCaseRunner] Finished running SoapUI testcase [Test_fieldsParameter], time taken: 384ms, status: FINISHED12:09:26,640 INFO [SoapUIProTestCaseRunner] Assertion [Match content of [errorCode]] has status VALID12:09:26,641 INFO [SoapUIProTestCaseRunner] Assertion [Match content of [message]] has status VALID12:09:26,641 INFO [SoapUIProTestCaseRunner] Assertion [Valid HTTP Status Codes] has status VALID12:09:26,641 INFO [SoapUIProTestCaseRunner] running step [OtherSortBy]12:09:26,643 DEBUG [HttpClientSupport$SoapUIHttpClient] Stale connection check12:09:26,645 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 1 to execute request12:09:26,646 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Sending request: GET /api/review/v1/questions?prodId=570043&_sortby=other HTTP/1.112:09:26,666 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 500 Internal Server Error12:09:26,667 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection 0.0.0.0:41475<->23.6.55.1:80 shut down12:09:26,667 DEBUG
Please have a look, this proves the string captured is the first:
str = "Match 1\n1. 500 Internal Server Error\nMatch 2\n1. 500 Internal Server Error\nMatch 3\n1. 500 Internal Server Error"
re = /(500 Internal Server Error)/
mdata = re.match(str)
puts mdata.begin(1)
puts mdata
Output of a sample program proving it is the first occurrence (index of 12 in the input string):
12
500 Internal Server Error

Resources