To extract the target from within the message, use this regex:
/ora-\d{0,7}/i
I looks like you're using ruby, so here's the code to get the target from a longer string:
code = m.message.match(/ora-\d{0,7}/i)[0]
Question
Am trying to match a particular string in Cinch bot framework .
So my current code works fine but only fails if the string comes with some extra words .e.g
say am trying to match only "hello-1234" then it responds properly but if am putting like "common hello-1234 " or "hello-1234 closing" then the code fails.
Could anybody can guide my how i can get rid of this .
Code :
require 'cinch'
require 'uri'
require 'nokogiri'
require 'net/https'
class Jira
include Cinch::Plugin
listen_to :message
def listen(m)
rx = config.jira.regex
if md = m.message.match(rx)
url = "#{config.jira.url}#{m.message.upcase}"
response = httpget url
details = Nokogiri::HTML response
config.jira.regex = /\b(ora)-(\d{0,7})\b/i
with this regex its matching ora-1234567. say i have "start ora-1234" or ora-1234 end" in above case how it should ignore the start and end and match only "ora-1234"
Solution
To extract the target from within the message, use this regex:
/ora-\d{0,7}/i
I looks like you're using ruby, so here's the code to get the target from a longer string:
code = m.message.match(/ora-\d{0,7}/i)[0]
OTHER TIPS
To obtain the portion of a message as a variable just do something like this:
listen: /(ora-\d{0,7})/i
def listen(m, jiraid)
url = "#{config.jira.url}#{jiraid}"
response = httpget url
details = Nokogiri::HTML response
Any regex groups [the bits in ()'s] are passed to any relevant plugin methods as extra arguments.