Parsing information between two with JavaScript

I'm a newbie in JavaScript and now I'm trying to parsing all information between two words. For example I have:

ip nat translation max-sessions 20000 interface GigabitEthernet 0/0 ip nat static-napt tcp 444 self 444 ip nat static-napt tcp 448 self 448 ip nat static-napt udp 43161 self 43161 exit

Actually I want to receive all information (including the end of the line) between "interface" and "exit".


Using regexp:

var text = "ip nat translation max-sessions 20000\n\
interface GigabitEthernet 0/0\n\
ip nat static-napt tcp 444 self 444\n\
ip nat static-napt tcp 448 self 448\n\
ip nat static-napt udp 43161 self 43161\n\


The [\s\S] does the trick here, it matches spaces and non-spaces, hence all characters.

You can try this

var String=str.substring(str.lastIndexOf("interface"),str.lastIndexOf("exit")-1);

var string = 'ip nat translation max-sessions 20000'+
'interface GigabitEthernet 0/0'+
'ip nat static-napt tcp 444 self 444'+
'ip nat static-napt tcp 448 self 448'+
'ip nat static-napt udp 43161 self 43161'+

var info =string.substring(string.lastIndexOf("interface"),string.lastIndexOf("exit"));

Category:javascript Time:2019-01-02 Views:1

Related post

  • How to pass Facebook Session Information Between two Activities 2011-10-06

    I would like to pass Facebook session information between two acvtivities so that I can authenticate one user in 1st session and use that session information to post a message to a wall in 2nd activity. What's the way of doing this simple task? Shoul

  • python: sending information between two scripts 2010-06-18

    I have two Python scripts in two different locations and cannot be moved. What is the best way to send information between the two scripts? say for example in i had a string e.g. x = 'teststring' then i need variable 'x' passed to script2.

  • How can I parse a CSV string with Javascript? 2011-12-13

    I have the following type of string var string = "'string, duppi, du', 23, lala" I want to split the string into an array on each comma, but only the commas outside the single quotation marks. I cant figure out the right regex for the split... string

  • Include space between two words Javascript if() statement 2009-12-07

    I'm trying to validate a generic contact form that's provided by my CRM unfortunately they control the server side script that puts the information into the CRM. The name of some of the form fields have spaces in them. How can I accommodate for that?

  • What's the difference in debug information between gcc with and without "-ggdb1" option? 2010-10-11

    By default, gcc will add symbol table to the executable, so gdb will get a readable stack trace. Documentation for -ggdb1 option in gcc man page says: Level 1 produces minimal information, enough for making backtraces in parts of the program that you

  • Parsing information between known variables 2011-04-13

    I dont mean to be a bother and I know this has been asked a thousand times before but i'm just not understanding the concept. I was wondering if somebody could walk me through it, Here is what i'm trying to do: I have a set of information inside an h

  • how to parse remote xml file with javascript/jQuery and phonegap? 2011-06-07

    For phonegap development: is it possible to fetch remote data for phonegape? is it possible to fetch remote json/xml file using ajax/jquery ? XmlHttpRequest can fetch remote xml file ? also any suggestion for it or important link. --------------Solut

  • Share information between two load-balanced IIS servers 2011-06-13

    I've two load-balanced IIS servers, and I need to share some information between them. The information is not related to the user session, so I don't see how a session state provider could help here. I cannot use the database (requirement), and appar

  • How to display route information between two points in Android? 2010-02-03

    I am able to show the route between two geo points in android using google map. Now i want to know how to guide the user like turn right, take left; likewise should display message. How can we achieve this? --------------Solutions------------- There

  • MySQL difference of two rows between two with PHP mysql_num_rows function? 2012-01-12

    Is it possible to somehow calc the difference between two rows of one table? I tried this, but it doesnt work: $diff = mysql_num_rows(" SELECT (`used`-`paid`) FROM `coupons_codes` WHERE `cid`='".$data['cid']."'"); --------------Solutions-------------

  • working with asynctask and json parsing simulataneously between two activities 2011-10-11

    i need some suggestion on how to go about this specific android problem: activity A passes an intent to activity B, B reads it, makes an API call, B receives response, parses it, and updates its views from the response now it works fine except fr a 2

  • How to parse calendar file dates with JavaScript? 2011-12-28

    We need to use JavaScript on the browser to read and parse calendar files (.ics) (also called iCal formats). I wrote a custom function to read these values and then use the JavaScript Date() function to make a data object. Is any easier and better wa

  • How to extract information between two unique words in a large text file 2012-02-10

    I have about 150 text files filled with character information. Each file contains two unique words ()alpha and bravo and i want to extract the text between these unique words and write it to a different file. Manually i can CTRL+F for the two words a

  • Sharing information between two XUL applications 2010-02-27

    I am currently developing a toolbar and sidebar for firefox. I want to have the two share information, but upon loading the .js file I want them to share, it is loaded twice and has two instances instead of one. How can I get the toolbar and the side

  • Not able to parse local xml file with javascript 2011-11-08

    When i try to parse local xml file using simple javascript, the code after is not getting executed. <html> <head> <script type="text/javascript"> function createXMLHttpRequestObject() { if (window.XMLHttpRequest) { xhttp=ne

  • Sencha Touch 2: data intigration or how to share dynamic information between sencha and javascript 2012-03-25

    I'd like to start quick. What is my problem: Within ST2 I structured my application with the MVC pattern. I have a store, a model, a controler and the views (for more information scroll down). Workflow: I click a list item (List View with a list of e

  • Sending information between two Windows Froms in C# 2010-02-09

    This might be a novice question. :). Consider the following scenario. Suppose we have two windows forms that are already "loaded" (i.e You can see both the forms) Form 1 contains a textbox and a "submit" button while the form 2 contains a text lable.

  • IE 8 remove line break between nodes with JavaScript 2011-01-02

    Ok i have a list of HTML nodes which should be inline with no spacing between them. The problem is, that the nodes are written from a CMS and therefore will come with all sorts of linebreaks and spaces. Therefore I'm removing the spaces with JS using

  • How To Share Information Between Django and Javascript? 2011-01-17

    So I am pretty new to both Django and Javascript (I am using JQuery) and I am wondering if I am doing a hack or if there are more slick ways to send client-side displayed database ids to the django server-side. Here is my process: I have a dataTable

  • Parsing wiki templates calls with Javascript 2011-03-28

    All that I need is to split the wiki template call to parameter parts. In the very basic scenario it is just splitting by | so {{template|unnamed_parameter|param1=value1}} would be split to {{template, unnamed_parameter, param1=value1 and }}. But thi

Copyright (C), All Rights Reserved.

processed in 0.851 (s). 13 q(s)