Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:23:00+00:00 2026-06-16T16:23:00+00:00

I’m facing at first sight a fairly trivial task but during a day I

  • 0

I’m facing at first sight a fairly trivial task but during a day I didn’t succeed to advance somehow in it. I need to process a string in velocity template.
The string has such view:

    Maj - [at552] - asdfghjkksfgh <br /> Avg - [at553] - asdfghjkksfgh <br /> etc

I need to replace text among [ ] symbols with following text:

    <a href="http://someaddress/at522">at522</a> (at522 is specific for 
    each [ ] block)

I tried so many approaches and none of them worked, so I don’t even know what snippets of code could I post here. An important detail is that I don’t have access to the java part of the application, just the object that is passed into the velocity template. I can’t use JavaScript because this a template for email. I would really appreciate every advice.

UPDATE
Here is the code that works fine for the first occurence of [ ]

#set ($scopeComment = $issue.getCustomFieldValue("customfield_10201").replaceAll("\n", "<br />"))
#set ($start = $scopeComment.indexOf("["))
#set ($end = $scopeComment.indexOf("]"))
#set ($substr = $scopeComment.substring($start, $end))
#set ($scopeComment = $scopeComment.replace($substr, "<a href=\"localhost/$substr\">$substr</a>"))

But I can’t make it work in a loop for all [ ] blocks
Here is one of the approach I’m trying

#foreach ($index in [0..$scopeComment.length()])
    #set($nextIndex = $index.index+1)
    #set($curChar = $scopeComment.substring($index.index, $nextIndex))
    #if ($curChar.equals("["))
        #set ($start = $count+1)
        #set ($end = $scopeComment.indexOf("]", count))
        #set ($sub = $scopeComment.substring($start, $end))
        $sub <br/>
    #end
#end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:23:01+00:00Added an answer on June 16, 2026 at 4:23 pm

    A RegExp will work in this case:

    #set ($var = $var.replaceAll('\[([a-z0-9]*)\]', '<a href="http://someaddress/$1">$1</a>'))
    

    Note that I used single quotes, and single backslash. Unlike Java, Velocity behaves differently when double or single quotes are used.

    There are many errors in your code. For example, what’s $index.index supposed to be? $index is an integer, so you should just use $index in your checks. Also, you use $count but that one isn’t defined anywhere, you probable mean $index as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.